We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
class Solution { public List<List<Integer>> threeSum(int[] nums) { Arrays.sort(nums); List<List<Integer>> ans = new ArrayList<>(); for(int i = 0; i < nums.length; i++){ if(i > 0 && nums[i] == nums[i-1]) continue; int left = i + 1, right = nums.length - 1; int num1 = nums[i]; while(left < right){ int num2 = nums[left], num3 = nums[right]; int sum = num1 + num2 + num3; if(left -1 > i && nums[left -1] == nums[left]){ left++; continue; } if(sum == 0) { ans.add(Arrays.asList(num1, num2, num3)); left++; } else if(sum > 0) right--; else if(sum < 0) left++; } } return ans; } }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
java
The text was updated successfully, but these errors were encountered: