题解 | #两数之和#
两数之和
https://www.nowcoder.com/practice/20ef0972485e41019e39543e8e895b7f
class Solution: def twoSum(self , numbers: List[int], target: int) -> List[int]: # write code here for index,num in enumerate(numbers): #如果元素大于目标,则看下一位 if num > target: continue # 寻找差值 if (target-num) in numbers[index+1:]: # 返回被减数的下标,差值的下标 return [index+1, numbers.index(target-num, index+1)+1]