https://leetcode.com/problems/two-sum/
from collections import defaultdict
class Solution:
def twoSum(self, nums: List[int], target: int) -> List[int]:
answer = [0, 0]
numDict = defaultdict(list)
for i in range(len(nums)) :
numDict[nums[i]].append(i)
for x in nums :
y = target - x
if numDict[y] :
if y == x:
if len(numDict[y]) == 1 :
continue
else :
answer = numDict[y]
else :
answer = [numDict[x][0], numDict[y][0]]
break
else :
continue
return answer