Open MiaoRain opened 4 years ago
class Solution:
def twoSum(self, nums: List[int], target: int) -> List[int]:#nums:[11,15,2,7], target:9
dic = {}
for i in range(len(nums)):
if target-nums[i] not in dic:
dic[nums[i]] = i
print(dic)#{11: 0} {11: 0, 15: 1} {11: 0, 15: 1, 2: 2}
else:
return [dic[target-nums[i]], i] #[2,3]