1.两数之和
key是数字,value是index,空间换时间
class Solution:
def twoSum(self, nums: List[int], target: int) -> List[int]:
index = {}
for i, num in enumerate(nums):
if target - num in index:
return [index[target - num], i]
index[num] = i