两数相加
https://leetcode-cn.com/problems/two-sum/submissions/ (opens new window)
class Solution(object):
def twoSum(self, nums, target):
"""
:type nums: List[int]
:type target: int
:rtype: List[int]
"""
hashmap = dict()
for i, num in enumerate(nums):
if(target-num in hashmap):
return [hashmap[target-num], i]
hashmap[num] = i