1. Two Sum
Given nums = [2, 7, 11, 15], target = 9,
Because nums[0] + nums[1] = 2 + 7 = 9,
return [0, 1].class Solution(object):
def twoSum(self, nums, target):
"""
:type nums: List[int]
:type target: int
:rtype: List[int]
"""
record = {} # to record if show before
for i in range(len(nums)):
if target-nums[i] in record: # if show before
return [record[target-nums[i]], i]
else:
record[nums[i]] = iLast updated