Skip to content

Instantly share code, notes, and snippets.

@yuuri
Created June 3, 2020 08:42
Show Gist options
  • Save yuuri/665f6906ceefa753f7bff63c9913303d to your computer and use it in GitHub Desktop.
Save yuuri/665f6906ceefa753f7bff63c9913303d to your computer and use it in GitHub Desktop.
def two_sum(number_list,target):
hash_dict = dict()
for key,value in enumerate(number_list):
hash_dict.update({value: key})
for i, number in enumerate(number_list):
j = hash_dict.get(target - number)
if j is not None and j != i:
return [i,j]
number_list = [11, 2, 7, 15]
target = 9
result = two_sum(number_list, target)
print(result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment