# Python simple solution based on twoSum

• ``````def threeSum(self, nums):
negtiveNum=dict()
positiveNum=dict()
hasZero=0
results=[]
for num in nums:
if num>0:
elif num<0:
else:
hasZero+=1

#when 0 0 0
if hasZero>2:
results.append([0,0,0])

#when -x 0 x:
if hasZero>0:
for key in negtiveNum:
result=[]
if positiveNum.__contains__(-key):

#when -x y z
for key in negtiveNum:
results=self.twoSum(key,positiveNum,results)

#when -x -y z
for key in positiveNum:
results=self.twoSum(key,negtiveNum,results)
return results

def twoSum(self,target,numdict,results):
usedSet=set()
for key in numdict:
result=[]
if not usedSet.__contains__(key):
if numdict.__contains__(-target-key) :
if -target-key == key and numdict.get(key)>1:
elif -target-key != key:
return results

result=[]
result.append(num1)
result.append(num2)
result.append(num3)
return result

if map.__contains__(num):
map[num]+=1
else:
map[num]=1
return map``````

• My sort sol using map

``````def twoSum(self, nums, target):
sol = set()
n_set = set()
for num in nums:
if num in n_set:
tup = tuple( sorted([num, target-num, -target]) )

return sol

def threeSum(self, nums):
sol = set()
for i, n in enumerate(nums):
sol = sol.union( self.twoSum(nums[i+1:], -n) )

return list(sol)``````

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.