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 08f4da9 commit ab95a95Copy full SHA for ab95a95
3sum/hi-rachel.py
@@ -0,0 +1,17 @@
1
+# O(n^2) time, O(n) space
2
+
3
+class Solution:
4
+ def threeSum(self, nums: List[int]) -> List[List[int]]:
5
+ triplets = set()
6
7
+ for i in range(len(nums) - 2):
8
+ seen = set()
9
+ for j in range(i + 1, len(nums)):
10
+ complement = -(nums[i] + nums[j])
11
+ if complement in seen:
12
+ triplet = [nums[i], nums[j], complement]
13
+ triplets.add(tuple(sorted(triplet)))
14
+ seen.add(nums[j])
15
16
+ return list(triplets)
17
0 commit comments