(int[] nums)
| 1 | /** Problem: https://leetcode.com/explore/interview/card/google/59/array-and-strings/3049/ */ |
| 2 | class Solution { |
| 3 | public List<List<Integer>> threeSum(int[] nums) { |
| 4 | List<List<Integer>> results = new ArrayList<>(); |
| 5 | |
| 6 | Arrays.sort(nums); |
| 7 | |
| 8 | for (int i = 0; i < nums.length; i++) { |
| 9 | if (i != 0 && nums[i] == nums[i - 1]) { |
| 10 | continue; |
| 11 | } |
| 12 | twoSum(i, nums, results); |
| 13 | } |
| 14 | |
| 15 | return results; |
| 16 | } |
| 17 | |
| 18 | private void twoSum(int i, int[] nums, List<List<Integer>> results) { |
| 19 | int leftPointer = i + 1; |