Created
June 3, 2020 08:42
-
-
Save yuuri/665f6906ceefa753f7bff63c9913303d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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