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 0bc32ec commit a01d15dCopy full SHA for a01d15d
3sum/jinah92.py
@@ -0,0 +1,19 @@
1
+# 공간복잡도 : O(1), 시간복잡도 : O(N^2)
2
+class Solution:
3
+ def threeSum(self, nums: List[int]) -> List[List[int]]:
4
+ three_sums = set()
5
+ nums.sort()
6
+
7
+ for i in range(len(nums)-2):
8
+ low, high = i + 1, len(nums)-1
9
+ while low < high:
10
+ three_sum = nums[i] + nums[high] + nums[low]
11
+ if three_sum < 0:
12
+ low += 1
13
+ elif three_sum > 0:
14
+ high -= 1
15
+ else:
16
+ three_sums.add((nums[i], nums[high], nums[low]))
17
+ low, high = low+1, high-1
18
19
+ return list(three_sums)
0 commit comments