给定已按升序排序的整数数组,找到两个数字,使它们的和等于特定的目标数字。
返回它们的下标加1
class Solution(object):
def twoSum(self, numbers, target):
"""
:type numbers: List[int]
:type target: int
:rtype: List[int]
"""
Dict = dict()
for i ,num in enumerate(numbers):
if target - num in Dict:
return [Dict[target - num]+1,i+1]
Dict[num] = i