```
def threeSum(self, nums):
d=dict()
n=len(nums)
ans=[]
for num in nums:
if num in d:
d[num]+=1
else:
d[num]=1
for i in range(n-1):
for j in range(i+1,n):
if -(nums[i]+nums[j]) in d:
temp=sorted([nums[i],nums[j],-nums[i]-nums[j]])
if temp in ans:
continue
if nums[i]==nums[j]==0:
if d[0]!=3:
continue
if nums[i]==nums[j] and nums[j]!=0:
if d[nums[i]]!=2:
continue
if -nums[i]-nums[j]==nums[j] and nums[j]!=0:
if d[nums[j]]!=2:
continue
ans.append(temp)
return ans
```