Last active
June 28, 2019 11:43
-
-
Save Desolve/e936fe7cbad8aa7810eeffacebadda41 to your computer and use it in GitHub Desktop.
0001 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: | |
def twoSum(self, nums: 'List[int]', target: 'int') -> 'List[int]': | |
numMap = {} | |
for i in range(len(nums)): | |
if numMap.__contains__(target-nums[i]): | |
return [numMap.get(target-nums[i]), i] | |
else: | |
numMap[nums[i]] = i |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment