class Solution(object):
def twoSum(self, numbers, target):
"""
:type numbers: List[int]
:type target: int
:rtype: List[int]
"""
num_dict={}
num_len=len(numbers)
for i in range(num_len):
if (target - numbers[i]) in num_dict:
return [num_dict[(target - numbers[i])],i+1]
else:
num_dict[numbers[i]]=i+1
leetcode 167 Two Sum II - Input array is sorted
Jun 1, 2017