摘要: 非In-place很好做,就是纸上画一个然后转一下举个例子 1 public void rotate(int[][] matrix) { 2 if(matrix == null || matrix.length == 0) { 3 return; 4 } 5 int n = matrix.lengt 阅读全文
posted @ 2016-03-02 04:55 warmland 阅读(159) 评论(0) 推荐(0) 编辑
摘要: 单纯做出来倒是没什么难度,但是优化不优化就需要多想想了。 自己的思路大概是: 1. 为一组anagram建HashMap的一条记录,key是这个词转成charArray的string,因为anagram字母排序后是一样的,value是一个List,里面装的是遇到的词 2.扫完之后遍历map,对每个l 阅读全文
posted @ 2016-03-02 03:54 warmland 阅读(234) 评论(0) 推荐(0) 编辑
摘要: 这道题没什么难度,但是之前看到过一种方法写得很好看。 因为这道题不是加上一位数,是加1,所以只有两种情况: 1. 该位是9,所以变成0,循环继续 2. 该位不是9,那就这位+1,然后返回 如果进行完了循环仍没有返回,说明整个数都是999999,那么就需要补一位,并且这个数是类似于100000...这 阅读全文
posted @ 2016-02-29 10:18 warmland 阅读(203) 评论(0) 推荐(0) 编辑
摘要: 只比1多了一句话 if(i > 0 && used[i-1] == true && nums[i] == nums[i-1]){ continue; } 1 public List<List<Integer>> permute(int[] nums) { 2 List<List<Integer>> 阅读全文
posted @ 2016-02-29 04:15 warmland 阅读(106) 评论(0) 推荐(0) 编辑
摘要: 和combinations比起来,需要多加一个used的数组标记这个数字有没有被用过。 1 public List<List<Integer>> permute(int[] nums) { 2 List<List<Integer>> res = new ArrayList<List<Integer> 阅读全文
posted @ 2016-02-29 04:00 warmland 阅读(133) 评论(0) 推荐(0) 编辑
摘要: 把两个数反过来算 1 public String multiply(String num1, String num2) { 2 if(num1 == null || num1.length() == 0 || num2 == null || num2.length() == 0) { 3 retur 阅读全文
posted @ 2016-02-29 03:34 warmland 阅读(128) 评论(0) 推荐(0) 编辑
摘要: 和39. Combination Sum基本是一样的,就是上一次迭代的时候从这个数的位置开始,不可以重复的话,就从下一个位置开始 1 public List<List<Integer>> combinationSum2(int[] candidates, int target) { 2 List<L 阅读全文
posted @ 2016-02-28 08:47 warmland 阅读(119) 评论(0) 推荐(0) 编辑
摘要: Backtracking问题 1 public List<List<Integer>> combinationSum(int[] candidates, int target) { 2 List<List<Integer>> res = new ArrayList<List<Integer>>(); 阅读全文
posted @ 2016-02-28 08:31 warmland 阅读(121) 评论(0) 推荐(0) 编辑
摘要: 方法一: 我直接用了java自带的split功能,比较赖皮 需要注意的就是只有空格的string会被裂成0个子串,所以处理一下 1 public int lengthOfLastWord(String s) { 2 if(s == null || s.length() == 0) { 3 retur 阅读全文
posted @ 2016-02-28 07:25 warmland 阅读(135) 评论(0) 推荐(0) 编辑
摘要: 没什么要说的,就是要好好看题= =…………我看错了两遍,蠢cry 1 public String countAndSay(int n) { 2 if(n == 0) { 3 return ""; 4 } 5 if(n == 1) { 6 return "1"; 7 } 8 String nth = 阅读全文
posted @ 2016-02-27 05:37 warmland 阅读(208) 评论(0) 推荐(0) 编辑