Created
November 21, 2023 05:54
-
-
Save Ayoush/d3ccafefa6caded1b94cfbcbb72519d9 to your computer and use it in GitHub Desktop.
two sum
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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