File tree Expand file tree Collapse file tree 1 file changed +34
-1
lines changed Expand file tree Collapse file tree 1 file changed +34
-1
lines changed Original file line number Diff line number Diff line change 1
1
import java .util .*;
2
+
3
+ class Solution {
4
+ public List <List <Integer >> threeSum (int [] nums ) {
5
+ Arrays .sort (nums );
6
+ Set <List <Integer >> set = new HashSet <>();
7
+ for (int i = 0 ; i < nums .length && nums [i ] <= 0 ; i ++) {
8
+ int j = i +1 ;
9
+ int k = nums .length - 1 ;
10
+ while (j < k ) {
11
+ int sum = nums [i ] + nums [j ] + nums [k ];
12
+ if (sum > 0 ) {
13
+ k --;
14
+ continue ;
15
+ }
16
+
17
+ if (sum < 0 ) {
18
+ j ++;
19
+ continue ;
20
+ }
21
+
22
+ set .add (List .of (nums [i ], nums [j ], nums [k ]));
23
+ j ++;
24
+ k --;
25
+ }
26
+ }
27
+
28
+ return new ArrayList <>(set );
29
+ }
30
+ }
31
+
32
+ /*
33
+ import java.util.*;
2
34
import java.util.stream.Collectors;
3
35
4
36
class Solution {
@@ -51,4 +83,5 @@ public boolean equals(Object o) {
51
83
public int hashCode() {
52
84
return Objects.hash(triplet[0], triplet[1], triplet[2]);
53
85
}
54
- }
86
+ }
87
+ */
You can’t perform that action at this time.
0 commit comments