Skip to content

Commit bd601c6

Browse files
committed
solved : 3sum
1 parent 8f0f654 commit bd601c6

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

3sum/ayleeee.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# 투포인터를 활용해보기
2+
3+
def threeSum(self, nums: List[int]) -> List[List[int]]:
4+
n = len(nums)
5+
nums.sort()
6+
result = set()
7+
for i in range(n):
8+
l,r = i+1,n-1
9+
while l<r:
10+
res = nums[i] + nums[l] + nums[r]
11+
if res < 0:
12+
l += 1
13+
elif res > 0:
14+
r -= 1
15+
else:
16+
result.add((nums[i], nums[l], nums[r]))
17+
l += 1
18+
return list(result)
19+

0 commit comments

Comments
 (0)