We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent d35392f commit 7bb6913Copy full SHA for 7bb6913
3sum/Sung-Heon.py
@@ -0,0 +1,33 @@
1
+class Solution:
2
+ def threeSum(self, nums: List[int]) -> List[List[int]]:
3
+ nums.sort()
4
+ result = []
5
+ n = len(nums)
6
+
7
+ for i in range(n - 2):
8
+ if i > 0 and nums[i] == nums[i - 1]:
9
+ continue
10
11
+ left = i + 1
12
+ right = n - 1
13
14
+ while left < right:
15
+ current_sum = nums[i] + nums[left] + nums[right]
16
17
+ if current_sum == 0:
18
+ result.append([nums[i], nums[left], nums[right]])
19
20
+ while left < right and nums[left] == nums[left + 1]:
21
+ left += 1
22
+ while left < right and nums[right] == nums[right - 1]:
23
+ right -= 1
24
25
26
27
28
+ elif current_sum < 0:
29
30
+ else:
31
32
33
+ return result
0 commit comments