ITeye博客

OJ_leetcode

共 23 篇文章

4Sum

本来以为只要在3Sum外面再包一层循环就好了,可是。。。在Judge Large的时候还是超时了 呜呜呜 [code="java"] public class Solution { public ArrayList> fourSum(int[] num, int target) { Arrays.sort(num); ArrayList> results = new ArrayList>(); ArrayList tempList; for (int i = 0; i < num.length - 3; ++i) for (int j = i + 1; j < num.length - 2;…

2012-10-27 22:49 · OJ_leetcode

3Sum Closest

这题的思路和3Sum一样,只是要考虑一下k在j+1之后是不是需要减1,因为不是0而是绝对值最小,所以有点难考虑= = 我就懒得去想直接没-1 汗啊 public class Solution { public int threeSumClosest(int[] num, int target) { Arrays.sort(num); int tempClose = Integer.MAX_VALUE; int tempsum = Integer.MAX_VALUE; for (int i = 0; i != num.length; ++i){ int k = num.length - 1; …

2012-10-27 21:08 · OJ_leetcode · Java

3sum

一直没看清英文题目,导致各种WA!唉唉唉。。。 通过Judge Small后: [code="java"] public class Solution { public ArrayList> threeSum(int[] num) { int length = num.length; ArrayList> results = new ArrayList>(); ArrayList list; for (int i = 0; i < length - 2; ++i) for (int j = i + 1; j < length - 1; ++j) for (int k = j + 1; k <…

2012-10-27 01:51 · OJ_leetcode · Java