Skip to content

Instantly share code, notes, and snippets.

@hectorip
Created September 14, 2021 04:39
Show Gist options
  • Save hectorip/395f4718183cab9fd92cdff9582f794f to your computer and use it in GitHub Desktop.
Save hectorip/395f4718183cab9fd92cdff9582f794f to your computer and use it in GitHub Desktop.
def twoSum(self, nums: List[int], target: int) -> List[int]:
past = {}
for i, e in enumerate(nums):
complement = target - e
j = past.get(complement, None)
if j is not None:
return [i, j]
past[e] = i
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment