//双指针,不过因为是三个数所以左侧是两个下标class Solution {public List<List<Integer>> threeSum(int[] nums) {int n = nums.length;Arrays.sort(nums);List<List<Integer>> ans = new ArrayList<List<Integer>>();for(int i = 0; i < n; i++){if(i > 0 && nums[i] == nums[i - 1]) continue;int target = -nums[i];int k = n - 1;for(int j = i + 1; j < n; j++){if(j > i + 1 && nums[j] == nums[j - 1]) continue;while(j < k && nums[j] + nums[k] > target){k--;}if(j == k) break;if(nums[j] + nums[k] == target){List<Integer> tmp = new ArrayList<>();tmp.add(nums[i]);tmp.add(nums[j]);tmp.add(nums[k]);ans.add(tmp);}}}return ans;}
}