Skip to content

Instantly share code, notes, and snippets.

@liketheflower
Created December 11, 2019 17:17
Show Gist options
  • Save liketheflower/fb24d5195ff95b3023780640118a9af3 to your computer and use it in GitHub Desktop.
Save liketheflower/fb24d5195ff95b3023780640118a9af3 to your computer and use it in GitHub Desktop.
class Solution:
def threeSum(self, nums: List[int]) -> List[List[int]]:
nums.sort()
res = set()
for i in range(len(nums)-2):
a = nums[i]
for j in range(i+1, len(nums)-1):
b = nums[j]
c = -(a+b)
if c < nums[j+1]:
continue
idx = bisect.bisect_left(nums[j+1:], c)
if idx+j+1>=len(nums) or nums[idx+j+1]!=c:
continue
else:res.add((a,b,c))
return [list(r) for r in res]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment