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 915c79c commit ff4aa6dCopy full SHA for ff4aa6d
3sum/mandoolala.py
@@ -0,0 +1,21 @@
1
+from typing import List
2
+
3
+class Solution:
4
+ def threeSum(self, nums: List[int]) -> List[List[int]]:
5
+ answer = set()
6
+ sorted_nums = sorted(nums)
7
8
+ for i in range(len(nums) - 2):
9
+ low, high = i + 1, len(nums) - 1
10
+ while low < high:
11
+ three_sum = sorted_nums[i] + sorted_nums[low] + sorted_nums[high]
12
+ if three_sum == 0:
13
+ answer.add((sorted_nums[i], sorted_nums[low], sorted_nums[high]))
14
+ low += 1
15
+ high -= 1
16
+ elif three_sum < 0:
17
18
+ elif three_sum > 0:
19
20
+ return list(answer)
21
0 commit comments