Leetcode: Two Sum, Python3
December 18, 2019•62 words
29 / 29 test cases passed
Status: Accepted
Runtime: 48 ms (beats 91.25% of submissions
Memory Usage: 14 MB (beats 65.58% of submissions)
class Solution:
def twoSum(self, nums: List[int], target: int) -> List[int]:
numMap = {}
for i in range(0, len(nums)):
num = nums[i]
complement = target - num
if complement in numMap.keys():
return numMap[complement], i
else:
numMap[num] = i