题解 | #两数之和#
两数之和
https://www.nowcoder.com/practice/20ef0972485e41019e39543e8e895b7f
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param numbers int整型一维数组 # @param target int整型 # @return int整型一维数组 # class Solution: def twoSum(self , numbers: List[int], target: int) -> List[int]: # write code here ans_dict = {} for i, num in enumerate(numbers): if target - num in ans_dict: return [ans_dict[target-num]+1, i+1] else: ans_dict[num]=i