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 1a843e3 commit 0b0a799Copy full SHA for 0b0a799
3sum/yayyz.py
@@ -0,0 +1,25 @@
1
+class Solution:
2
+ def threeSum(self, nums: List[int]) -> List[List[int]]:
3
+ nums.sort()
4
+ result = []
5
+ for i in range(len(nums)):
6
+ if i > 0 and nums[i] == nums[i - 1]:
7
+ continue
8
+
9
+ left = i + 1
10
+ right = len(nums) - 1
11
+ while left < right:
12
+ total = nums[i] + nums[left] + nums[right]
13
+ if total < 0:
14
+ left += 1
15
+ elif total > 0:
16
+ right -= 1
17
+ else:
18
+ result.append([nums[i], nums[left], nums[right]])
19
20
21
+ while left < right and nums[left] == nums[left -1]:
22
23
+ while left < right and nums[right] == nums[right + 1]:
24
25
+ return result
0 commit comments