Array
不刷脸皮要刷题
这个作者很懒,什么都没留下…
展开
-
3 sum
注意跳过重复的元素!//时间复杂度: O(n^2)public class Solution { public List> threeSum(int[] num) { List> res = new ArrayList<>(); if(num == null || num.length < 3) return res; Arra转载 2014-11-10 11:27:21 · 289 阅读 · 1 评论 -
Maximum Product Subarray
最值问题的第二种思路,保存局部最优,更新全局最优求P转载 2014-10-19 20:53:57 · 230 阅读 · 0 评论 -
Sudoku Solver
找到存在的解:DFS + Backtracking因为ji转载 2014-10-13 00:12:31 · 254 阅读 · 0 评论 -
Permutation I,II
还要有多典型的DFS + backtracking,之前写的乱七八糟凑出来的,后来用了这个si转载 2014-10-30 23:52:15 · 264 阅读 · 0 评论 -
Valid Sudoku
1.标记 Visited:a. 直接在array中改 (bi'r转载 2014-10-12 23:20:10 · 257 阅读 · 0 评论 -
Gray Code
public class Solution { public List grayCode(int n) { List res = new ArrayList<>(); res.add(0); if(n == 0) return res; res = grayCode(n-1); for(int转载 2014-11-12 00:43:49 · 260 阅读 · 0 评论 -
Search for a range
两次二分public class Solution { public int[] searchRange(int[] A, int target) { int[] res = new int[2]; res[0] = -1; res[1] = -1; int beg = 0; in转载 2014-10-09 12:14:27 · 304 阅读 · 0 评论 -
Remove duplicates from sorted array I
Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length.Do not allocate extra space for another array, you must do this in place with转载 2014-10-09 11:28:02 · 237 阅读 · 0 评论 -
Remove duplicates from sorted array II
Follow up for "Remove Duplicates":What if duplicates are allowed at most twice?For example,Given sorted array A = [1,1,1,2,2,3],Your function should return length = 5, and A is now [1,1,2,转载 2014-10-09 11:49:50 · 222 阅读 · 0 评论 -
Trapping rain water
array的找规律的题public class Solution { public int trap(int[] A) { int sum = 0; int maxInd = -1; int max = -1; //find the highest bars; for (int i = 0; i < A.leng转载 2014-10-04 04:30:22 · 290 阅读 · 0 评论 -
Container with most water
two pointers, 两头往中间走转载 2014-11-10 12:19:53 · 215 阅读 · 0 评论 -
3 sum closest
two pointers O(n^2)public class Solution { public int threeSumClosest(int[] num, int target) { if (num == null || num.length <= 2) return 0; Arrays.sort(num); int closest转载 2014-11-10 11:43:02 · 314 阅读 · 0 评论 -
Gas Station
There are N gas stations along a circular route, where the amount of gas at station i is gas[i].You have a car with an unlimited gas tank and it costs cost[i] of gas to travel from station i to转载 2014-10-21 20:58:48 · 254 阅读 · 0 评论