Skip to content

Instantly share code, notes, and snippets.

@Ayoush
Created November 21, 2023 05:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ayoush/d3ccafefa6caded1b94cfbcbb72519d9 to your computer and use it in GitHub Desktop.
Save Ayoush/d3ccafefa6caded1b94cfbcbb72519d9 to your computer and use it in GitHub Desktop.
two sum
class Solution(object):
def twoSum(self, nums, target):
hash_map = {}
for i in range(len(nums)):
ans = target - nums[i]
if ans in hash_map.keys():
return([hash_map[ans], i])
hash_map[nums[i]] = i
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment