摘要: 运用dfs查找用substring不太好 可能弄到空的 还是用start记录位置比较好 dfs刚开始先判断条件 判断完再干别的会比较方便 visited 每次用完要变回false 否则有同一个点搜索路径退回的时候,那边就不能被继续搜索了 阅读全文
posted @ 2018-08-27 10:19 jasoncool1 阅读(126) 评论(0) 推荐(0) 编辑
摘要: https://leetcode.com/problems/rotate-image/discuss/159913/found-a-general-method 刚发现一个套路了,对于这类matrix翻转的题目,一般都是经过一个中间过渡状态,比如:1,2,34,5,67,8,9要变成:7,4,18, 阅读全文
posted @ 2018-08-27 07:08 jasoncool1 阅读(267) 评论(0) 推荐(0) 编辑
摘要: 设置toprow bottomrow leftcol rightcol来标记边界,然后对每一条边界进行循环 要是list的size等于matrix的size的话 就表明结束了 阅读全文
posted @ 2018-08-27 06:11 jasoncool1 阅读(300) 评论(0) 推荐(0) 编辑
摘要: O(m + n)space 简单的 row和col分别设置标志 阅读全文
posted @ 2018-08-27 05:24 jasoncool1 阅读(111) 评论(0) 推荐(0) 编辑
摘要: A little trick is using i <= x / i for comparison, instead of i * i <= x, to avoid exceeding integer upper limit. 二分法查找比较快 阅读全文
posted @ 2018-08-27 04:34 jasoncool1 阅读(129) 评论(0) 推荐(0) 编辑
摘要: 用二分法recursively的解决这道题 否则会有runtime error 阅读全文
posted @ 2018-08-27 03:36 jasoncool1 阅读(144) 评论(0) 推荐(0) 编辑
摘要: 1 class Solution { 2 public void reorderList(ListNode head) { 3 if(head == null) return; 4 if(head.next == null) return; 5 if(head.next.next == null) return; 6 Li... 阅读全文
posted @ 2018-08-18 07:16 jasoncool1 阅读(120) 评论(0) 推荐(0) 编辑
摘要: 1 class Solution { 2 public ListNode removeNthFromEnd(ListNode head, int n) { 3 if(head == null) return head; 4 if(head.next == null) return null; 5 ListNode node1 = head... 阅读全文
posted @ 2018-08-18 00:46 jasoncool1 阅读(148) 评论(0) 推荐(0) 编辑
摘要: 1 //10 ms 2 class Solution { 3 public ListNode mergeTwoLists(ListNode l1, ListNode l2) { 4 if(l1 == null) return l2; 5 if(l2 == null) return l1; 6 ListNode head = nu... 阅读全文
posted @ 2018-08-18 00:26 jasoncool1 阅读(86) 评论(0) 推荐(0) 编辑
摘要: 一个快一个慢 要是重合了就有cycle 阅读全文
posted @ 2018-08-17 23:34 jasoncool1 阅读(112) 评论(0) 推荐(0) 编辑