Created
September 11, 2014 07:18
-
-
Save nypgand1/6bc80e52d60c3b008280 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
class Solution: | |
# @return a tuple, (index1, index2) | |
def twoSum(self, num, target): | |
num_index = dict() | |
for i, n in enumerate(num): | |
partner = str(target - n) | |
if partner in num_index: | |
return ( (num_index[partner]+1), (i+1) ) | |
else: | |
num_index[str(n)] = i |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment