Skip to content

Instantly share code, notes, and snippets.

@avagin
Created December 16, 2019 07:22
Show Gist options
  • Save avagin/83fb994104b65136ed0440ca00f7d85f to your computer and use it in GitHub Desktop.
Save avagin/83fb994104b65136ed0440ca00f7d85f to your computer and use it in GitHub Desktop.
class Solution(object):
def threeSum(self, nums):
"""
:type nums: List[int]
:rtype: List[List[int]]
"""
if len(nums) < 3:
return []
nums.sort()
r = []
i = 0;
maxv = nums[-1]
nums_set = set(nums)
n = len(nums)
a = nums[0] - 1
while True:
if i == n - 2:
break;
if i != 0 and a == nums[i]:
i+=1
continue
a = nums[i]
j = i + 1
b = nums[j] - 1
while True:
if j == n - 1:
break;
if b == nums[j]:
j += 1
continue
b = nums[j]
c = -a -b;
if b > c:
break
if c in nums_set:
new = [a,b,0 - a - b]
if c != b or nums[j + 1] == c:
r.append([a,b,0 - a - b])
j += 1
i += 1
if a > 0:
break
return r
print(Solution().threeSum([-1, 0, 1, 2, -1, -4]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment