Skip to content

Commit a01d15d

Browse files
committed
feat: 3sum 문제풀이
1 parent 0bc32ec commit a01d15d

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

3sum/jinah92.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)