forked from DaleStudy/leetcode-study
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHodaeSsi.py
More file actions
21 lines (18 loc) · 674 Bytes
/
HodaeSsi.py
File metadata and controls
21 lines (18 loc) · 674 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
class Solution:
def threeSum(self, nums: List[int]) -> List[List[int]]:
answerSet = set()
nums.sort()
for i in range(len(nums) - 2):
leftIdx = i + 1
rightIdx = len(nums) - 1
while leftIdx < rightIdx:
sum = nums[i] + nums[leftIdx] + nums[rightIdx]
if sum < 0:
leftIdx += 1
elif sum > 0:
rightIdx -= 1
else:
answerSet.add((nums[i], nums[leftIdx], nums[rightIdx]))
leftIdx = leftIdx + 1
rightIdx = rightIdx - 1
return list(answerSet)