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 84b3725 commit 09faf30Copy full SHA for 09faf30
3sum/printjin-gmailcom.py
@@ -1,8 +1,10 @@
1
class Solution:
2
def threeSum(self, nums):
3
- triplets = set()
+ triplets = []
4
nums.sort()
5
for i in range(len(nums) - 2):
6
+ if i > 0 and nums[i - 1] == nums[i]:
7
+ continue
8
low, high = i + 1, len(nums) - 1
9
while low < high:
10
three_sum = nums[i] + nums[low] + nums[high]
@@ -11,6 +13,10 @@ def threeSum(self, nums):
11
13
elif three_sum > 0:
12
14
high -= 1
15
else:
- triplets.add((nums[i], nums[low], nums[high]))
16
+ triplets.append([nums[i], nums[low], nums[high]])
17
+ while low < high and nums[low] == nums[low + 1]:
18
+ low += 1
19
+ while low < high and nums[high] == nums[high - 1]:
20
+ high -= 1
21
low, high = low + 1, high - 1
- return list(triplets)
22
+ return triplets
0 commit comments