class Solution(object):
def twoSum(self, nums, target):
"""
:type nums: List[int]
:type target: int
:rtype: List[int]
"""
map1={}
for i in range(len(nums)):
if map1.has_key(target-nums[i]):
return [map1[target-nums[i]],i]
else:
map1[nums[i]]=i
重点:
1、使用哈希表缩短运行时间
2、相同对象的哈希值相同