题解 | #两数之和# Python
两数之和
https://www.nowcoder.com/practice/20ef0972485e41019e39543e8e895b7f
暴力超时
转变哈希:
d = {}
for i in range(len(numbers)):
n = target - numbers[i]
if n not in d:
# 方便判断数值是否在字典里: key 是数组,value是Index
d[numbers[i]] = i
else:
return [d[n]+1,i+1]