Skip to content

Instantly share code, notes, and snippets.

@nypgand1
Created September 11, 2014 07:18
Show Gist options
  • Save nypgand1/6bc80e52d60c3b008280 to your computer and use it in GitHub Desktop.
Save nypgand1/6bc80e52d60c3b008280 to your computer and use it in GitHub Desktop.
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