class Solution(object):
def threeSum(self, nums):
"""
:type nums: List[int]
:rtype: List[List[int]]
"""
nums = sorted(nums)
N = len(nums)
if N < 3: return []
seen = set()
for i, n in enumerate(nums):
if i > 0 and nums[i-1] == nums[i]:continue
lo, hi = i+1, N-1
while lo < hi:
s = nums[lo]+nums[i]+nums[hi]
if s > 0:
hi -= 1
elif s < 0:
lo += 1
else:
seen.add((nums[i], nums[lo], nums[hi]))
lo+=1
hi-=1
return sorted(seen)