思路:存起来当前的值和下标 值当k 下标当v 然后判断target-v在不在里面字典里就行
class Solution:
def twoSum(self, nums: List[int], target: int) -> List[int]:
'''
思路:
用元素作为值,键作为索引
'''
dic = {}
for k,v in enumerate(nums):
if (target-v) not in dic:
dic[v] = k
else:
return [dic[target-v],k]