File tree Expand file tree Collapse file tree 1 file changed +4
-13
lines changed Expand file tree Collapse file tree 1 file changed +4
-13
lines changed Original file line number Diff line number Diff line change @@ -8,30 +8,21 @@ class Solution:
8
8
공간 복잡도는 둘다 O(1)
9
9
"""
10
10
def threeSum (self , nums : List [int ]) -> List [List [int ]]:
11
- result = []
11
+ result = set ()
12
12
nums .sort ()
13
13
14
- for i in range (len (nums )):
15
- if i > 0 and nums [i ] == nums [i - 1 ]:
16
- continue
17
-
14
+ for i in range (len (nums )):
18
15
left , right = i + 1 , len (nums ) - 1
19
16
while left < right :
20
17
total = nums [i ] + nums [left ] + nums [right ]
21
18
22
19
if total == 0 :
23
- result .append ([ nums [i ], nums [left ], nums [right ]] )
20
+ result .add (( nums [i ], nums [left ], nums [right ]) )
24
21
left += 1
25
22
right -= 1
26
-
27
- while left < right and nums [left ] == nums [left - 1 ]:
28
- left += 1
29
- while left < right and nums [right ] == nums [right + 1 ]:
30
- right -= 1
31
-
32
23
elif total < 0 :
33
24
left += 1
34
25
else :
35
26
right -= 1
36
27
37
- return result
28
+ return list ( result )
You can’t perform that action at this time.
0 commit comments