Subject description:
solution:
An ordered array of elements is used in the form dictionary indicates, whether there had been performed in a location other than the array for subtracting the target value in the array elements, as follows:
class Solution(object):
def twoSum(self, numbers, target):
"""
:type numbers: List[int]
:type target: int
"""
dic = {}
for index, value in enumerate(numbers):
dic[value] = index
for index, value in enumerate(numbers):
if dic.get(target - value) is not None:
return [index+1, dic.get(target - value)+1]