algorithm | February 10, 2020
def two_sum(nums, target):
for index1 in range(len(nums)):
for index2 in range(len(nums)):
if nums[i] + nums[j] == target:
return [i, j]
def two_sum(nums, target):
target_minus = []
for value in nums:
target_minus.append(target-value)
return [index for index in range(len(target_minus)) if target_minus[index] in nums]
def two_sum(nums, target):
index_map = {}
for i in range(len(nums)):
num = nums[i]
pair = target - num
if pair in index_map:
return [index_map[pair], i]
index_map[num] = i
return None