08 2018 档案

摘要:注意null的时候要单独判断 因为不能用val 阅读全文
posted @ 2018-08-28 22:16 jasoncool1
摘要:没啥特别 会longest palindromic substrings就可以 阅读全文
posted @ 2018-08-28 21:39 jasoncool1
摘要:把每个位置分成odd和even两种情况 两个指针分别向两边查找,看看最长的palindrome在哪里 这样复杂度比较低 全部遍历的话 timelimit exceed 阅读全文
posted @ 2018-08-28 21:05 jasoncool1
摘要:用stack 阅读全文
posted @ 2018-08-28 07:43 jasoncool1
摘要:1 //easy 2 //注意字符串长度可能不一样 3 4 class Solution { 5 public boolean isAnagram(String s, String t) { 6 if(s.length() != t.length()) return false; 7 char[] arr1 = s.toCharArray(... 阅读全文
posted @ 2018-08-28 06:48 jasoncool1
摘要:自己方法复杂度比较高 可以O(n)的方法,遍历一遍 用两个指针记录maxstring的位置 然后遇到跟hashmap里重复的就更新指针https://leetcode.com/problems/longest-substring-without-repeating-characters/discus 阅读全文
posted @ 2018-08-28 06:37 jasoncool1
摘要:同Subset就是要先进行排序,backtrack的时候不要把重复的加入list 阅读全文
posted @ 2018-08-28 01:27 jasoncool1
摘要:backtrack的思想https://blog.csdn.net/wonner_/article/details/80373871这个链接很好 subset中的backtrack要把最后一个param设置成现在进行遍历的位置,而且backtrack中的循环要在上一个position之后开始 阅读全文
posted @ 2018-08-28 01:14 jasoncool1
摘要:运用dfs查找用substring不太好 可能弄到空的 还是用start记录位置比较好 dfs刚开始先判断条件 判断完再干别的会比较方便 visited 每次用完要变回false 否则有同一个点搜索路径退回的时候,那边就不能被继续搜索了 阅读全文
posted @ 2018-08-27 10:19 jasoncool1
摘要: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
摘要:设置toprow bottomrow leftcol rightcol来标记边界,然后对每一条边界进行循环 要是list的size等于matrix的size的话 就表明结束了 阅读全文
posted @ 2018-08-27 06:11 jasoncool1
摘要:O(m + n)space 简单的 row和col分别设置标志 阅读全文
posted @ 2018-08-27 05:24 jasoncool1
摘要: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
摘要:用二分法recursively的解决这道题 否则会有runtime error 阅读全文
posted @ 2018-08-27 03:36 jasoncool1
摘要: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
摘要: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
摘要: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
摘要:一个快一个慢 要是重合了就有cycle 阅读全文
posted @ 2018-08-17 23:34 jasoncool1
摘要:熟悉了一下linkedlist的构造和处理 阅读全文
posted @ 2018-08-17 23:21 jasoncool1
摘要:要先sort之后 判断a.end b.start才能找出interval list可以用Collections.sort()进行排序 new Comparator<类型> 然后重写compare方法 返回数字就可以 阅读全文
posted @ 2018-08-17 05:20 jasoncool1
摘要:DFS把能遍历到的是1的都变成0,这样就能识别出一个岛。 阅读全文
posted @ 2018-08-17 03:01 jasoncool1
摘要:Queue使用时要尽量避免Collection的add()和remove()方法,而是要使用offer()来加入元素,使用poll()来获取并移出元素。它们的优点是通过返回值可以判断成功与否,add()和remove()方法在失败的时候会抛出异常。 如果要使用前端而不移出该元素,使用element( 阅读全文
posted @ 2018-08-17 00:57 jasoncool1
摘要:初次了解DFS实际代码 注意事项已标注 阅读全文
posted @ 2018-08-16 23:51 jasoncool1
摘要:1 //Old 2 class Solution { 3 public boolean canJump(int[] nums) { 4 int n = nums.length; 5 if(n == 0) return false; 6 if(n == 1) return true; 7 if(nums[0] =... 阅读全文
posted @ 2018-08-16 11:37 jasoncool1
摘要:没啥特别的 阅读全文
posted @ 2018-08-16 10:20 jasoncool1
摘要:Java String to int1.int a = Integer.parseInt(str);2.int b = Integer.valueOf(str).intValue(); Char to intint c1 = Character.getNumericValue(i); 考虑0的情况 阅读全文
posted @ 2018-08-16 09:21 jasoncool1
摘要:1 class Solution { 2 public int rob(int[] nums) { 3 int n = nums.length; 4 int[] res = new int[n]; 5 if(n == 0) return 0; 6 if(n == 1) return nums[0]; 7 ... 阅读全文
posted @ 2018-08-08 00:04 jasoncool1
摘要:1 class Solution { 2 public int rob(int[] nums) { 3 int n = nums.length; 4 int[] res = new int[n + 1]; 5 if(n == 0) return 0; 6 if(n == 1) return nums[0]; 7... 阅读全文
posted @ 2018-08-07 23:34 jasoncool1
摘要:1 class Solution { 2 public int combinationSum4(int[] nums, int target) { 3 int[] res = new int[target + 1]; 4 res[0] = 1; 5 for(int i = 1; i 0) { 8 ... 阅读全文
posted @ 2018-08-02 23:18 jasoncool1
摘要:打印字符串的一个字符用str.charAt()substring用str.subString() 要用这个字母之前几个能否组成word这样来考虑 https://leetcode.com/problems/word-break/discuss/43790/Java-implementation-us 阅读全文
posted @ 2018-08-02 05:20 jasoncool1
摘要:O(nlogn): Arrays.binarySearch()的返回值找到关键字从0开始,没找到关键字从1开始 dp数组记录的是从长度1开始,每个长度(1,2,3...)末端的最小值,因为往后遍历的时候,能大于之前值的数肯定能大于这个最小值。判断一个数的时候,找出比这个数大的最小的那个,把那个更新为 阅读全文
posted @ 2018-08-01 22:24 jasoncool1
摘要:1 //70% 2 class Solution { 3 public int coinChange(int[] coins, int amount) { 4 if(amount == 0) return 0; 5 int[]res = new int[amount + 1]; 6 for(int i = 0; i <= amo... 阅读全文
posted @ 2018-08-01 04:36 jasoncool1
摘要:1 class Solution { 2 public int climbStairs(int n) { 3 int[] s = new int[n + 1]; 4 s[1] = 1; s[0] = 1; 5 for(int i = 2; i <= n; i++) { 6 s[i] = s[i - 1] ... 阅读全文
posted @ 2018-08-01 01:38 jasoncool1
摘要:这个规律找的更好,规律是,从1开始,遇到偶数时,其1的个数和该偶数除以2得到的数字的1的个数相同,遇到奇数时,其1的个数等于该奇数除以2得到的数字的1的个数再加1 阅读全文
posted @ 2018-08-01 01:36 jasoncool1
摘要:0到n的sum减去已经存在的就是missing number 阅读全文
posted @ 2018-08-01 00:01 jasoncool1