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 0f20b2b commit 4b9aec2Copy full SHA for 4b9aec2
LeetCode Solutions/LeetCoding Challenge/October 2021 LeetCoding Challenge/3Sum.py
@@ -0,0 +1,25 @@
1
+class Solution:
2
+ def threeSum(self, nums: List[int]) -> List[List[int]]:
3
+ nums.sort()
4
+ triplets = []
5
+ length = len(nums)
6
+ for i in range(length-2):
7
+ if(i > 0 and nums[i] == nums[i-1]):
8
+ continue
9
+ left = i + 1
10
+ right = length - 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
+ triplets.append([nums[i], nums[left], nums[right]])
19
+ while(left < right and nums[left] == nums[left+1]):
20
21
+ while(left < right and nums[right] == nums[right-1]):
22
23
24
25
+ return triplets
0 commit comments