Skip to content

Commit

Permalink
feat: 3sum 문제풀이
Browse files Browse the repository at this point in the history
  • Loading branch information
jinah92 committed Dec 20, 2024
1 parent 0bc32ec commit a01d15d
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions 3sum/jinah92.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# 공간복잡도 : O(1), 시간복잡도 : O(N^2)
class Solution:
def threeSum(self, nums: List[int]) -> List[List[int]]:
three_sums = set()
nums.sort()

for i in range(len(nums)-2):
low, high = i + 1, len(nums)-1
while low < high:
three_sum = nums[i] + nums[high] + nums[low]
if three_sum < 0:
low += 1
elif three_sum > 0:
high -= 1
else:
three_sums.add((nums[i], nums[high], nums[low]))
low, high = low+1, high-1

return list(three_sums)

0 comments on commit a01d15d

Please sign in to comment.