added hashmap solution with fastest runtime

This commit is contained in:
Jacob Delgado 2023-08-02 22:34:36 -07:00
parent feb856028e
commit 10c4e5c6b0

View File

@ -10,6 +10,14 @@ def twoSum(nums, target):
#print(f'i is {nums[i]}, j is {nums[j]}') #print(f'i is {nums[i]}, j is {nums[j]}')
return [i,j] return [i,j]
#hashmap = {}
#for i in range(len(nums)):
#complacement = target - nums[i]
#if complacement in hashmap:
# return [i, hashmap[complacement]]
# else:
#hashmap[nums[i]] = i
print(twoSum([2,7,11,15], 9)) print(twoSum([2,7,11,15], 9))
print(twoSum([3,2,4], 6)) print(twoSum([3,2,4], 6))