摘要: 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 阅读(153) 评论(0) 推荐(0) 编辑
摘要: 打印字符串的一个字符用str.charAt()substring用str.subString() 要用这个字母之前几个能否组成word这样来考虑 https://leetcode.com/problems/word-break/discuss/43790/Java-implementation-us 阅读全文
posted @ 2018-08-02 05:20 jasoncool1 阅读(259) 评论(0) 推荐(0) 编辑
摘要: O(nlogn): Arrays.binarySearch()的返回值找到关键字从0开始,没找到关键字从1开始 dp数组记录的是从长度1开始,每个长度(1,2,3...)末端的最小值,因为往后遍历的时候,能大于之前值的数肯定能大于这个最小值。判断一个数的时候,找出比这个数大的最小的那个,把那个更新为 阅读全文
posted @ 2018-08-01 22:24 jasoncool1 阅读(161) 评论(0) 推荐(0) 编辑
摘要: 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 阅读(204) 评论(0) 推荐(0) 编辑
摘要: 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 阅读(120) 评论(0) 推荐(0) 编辑
摘要: 这个规律找的更好,规律是,从1开始,遇到偶数时,其1的个数和该偶数除以2得到的数字的1的个数相同,遇到奇数时,其1的个数等于该奇数除以2得到的数字的1的个数再加1 阅读全文
posted @ 2018-08-01 01:36 jasoncool1 阅读(82) 评论(0) 推荐(0) 编辑
摘要: 0到n的sum减去已经存在的就是missing number 阅读全文
posted @ 2018-08-01 00:01 jasoncool1 阅读(201) 评论(0) 推荐(0) 编辑
摘要: 1 class Solution { 2 // you need to treat n as an unsigned value 3 public int hammingWeight(int n) { 4 int res = 0; 5 for(int i = 0; i >>=1; 10 } 11 r... 阅读全文
posted @ 2018-07-31 23:32 jasoncool1 阅读(124) 评论(0) 推荐(0) 编辑
摘要: https://leetcode.com/problems/sum-of-two-integers/discuss/84277/One-liner-with-detailed-explanation https://stackoverflow.com/questions/9070937/adding 阅读全文
posted @ 2018-07-31 23:22 jasoncool1 阅读(122) 评论(0) 推荐(0) 编辑
摘要: >>>表示无符号右移,左边空出的位以0填充>>=右移赋值>>>=无符号右移赋值<<= 左移赋值<<左移 阅读全文
posted @ 2018-07-31 05:37 jasoncool1 阅读(139) 评论(0) 推荐(0) 编辑