MCPcopy Create free account
hub / github.com/DestinationFAANG/Destination-FAANG-Java-Solution / twoSum2

Method twoSum2

15 3sum/15 3-Sum.java:21–41  ·  view source on GitHub ↗
(int[] nums, int i, List<List<Integer>> result)

Source from the content-addressed store, hash-verified

19 }
20
21 void twoSum2(int[] nums, int i, List<List<Integer>> result){
22 int left = i+1;
23 int right = nums.length - 1;
24
25 while(left < right){
26 int sum = nums[i] + nums[left] + nums[right];
27
28 if(sum < 0){
29 ++left;
30 }
31 else if (sum > 0){
32 --right;
33 }
34 else{
35 result.add(Arrays.asList(nums[i], nums[left++], nums[right--]));
36 while(left < right && nums[left] == nums[left-1]){
37 ++left;
38 }
39 }
40 }
41 }
42}

Callers 1

threeSumMethod · 0.95

Calls 1

addMethod · 0.45

Tested by

no test coverage detected