标签:return blog pre style else i+1 .so color add
class Solution { public List<List<Integer>> threeSum(int[] nums) { List<List<Integer>> ret=new ArrayList<List<Integer>>(); Arrays.sort(nums); for(int i=0;i<nums.length-2;i++) if(i==0||nums[i]!=nums[i-1]) { int l=i+1; int r=nums.length-1; while(l<r) { int sum=nums[i]+nums[l]+nums[r]; if(sum==0) { ret.add(Arrays.asList(new Integer[]{nums[i], nums[l], nums[r]})); while(l<r&&nums[l]==nums[l+1])l++; while(l<r&&nums[r]==nums[r-1])r--; l++; r--; } else if(sum>0) r--; else l++; } } return ret; } }
标签:return blog pre style else i+1 .so color add
原文地址:http://www.cnblogs.com/asuran/p/7574280.html