Skip to content

Instantly share code, notes, and snippets.

@philippeback
Created April 1, 2019 20:40
Show Gist options
  • Save philippeback/9e383d5ecb5572a82a9fb337e9cb251c to your computer and use it in GitHub Desktop.
Save philippeback/9e383d5ecb5572a82a9fb337e9cb251c to your computer and use it in GitHub Desktop.
class Solution:
def wanted(this, number, target):
return target - number
def twoSum(self, nums: List[int], target: int) -> List[int]:
wanted_dict = {}
for i in range(0, len(nums)):
num = nums[i]
entry = (i, self.wanted(num,target))
wanted_dict[num]=entry
for i in range(0, len(nums)):
target_making_key = target - nums[i]
if target_making_key in wanted_dict:
(j, _) = wanted_dict[target_making_key]
if (i != j):
return (i,j)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment