Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public List<List<Integer>> threeSum(int[] nums) {
- Arrays.sort(nums);
- List<List<Integer>> L = new LinkedList<List<Integer>> ();
- Set<int[]> set = new HashSet<int[]> () ;
- int i = 0;
- int j , z;
- int sum = -1;
- while(i < nums.length-2){
- j = i + 1;
- z = nums.length-1;
- while(j < z){
- sum = nums[i] + nums[j] + nums[z];
- if(sum < 0)
- j++;
- else if(sum > 0)
- z--;
- else if (sum == 0){
- set.add( new int[] { nums[i], nums[j] , nums[z]} );
- break;
- }
- }
- i++;
- }
- for( int[] each : set){
- L.add(Arrays.asList(each[0], each[1], each[2]));
- }
- return L;
- }
Add Comment
Please, Sign In to add comment