题解 | #两数之和#
两数之和
https://www.nowcoder.com/practice/20ef0972485e41019e39543e8e895b7f
class Solution:
def twoSum(self , numbers: List[int], target: int) -> List[int]:
dict_index, lens = {}, len(numbers)
list_num = []
for num in range(0, lens, 1):
if target-numbers[num] in dict_index.keys():
list_num.append(dict_index[target-numbers[num]])
list_num.append(num+1)
return list_num
else:
dict_index[numbers[num]] = num+1
查看13道真题和解析