标签:blog val pre etc 记录 状态 code and question
key: build and search Hash table.
following up questions: Overflow value for target?
用Hash table记录之间的状态,思想类似DP
def twoSum(nums, target): d = {} n = len(nums) res = [] for i in range(n): if target - nums[i] in d: res = [d[target - nums[i]], i] else: d[nums[i]] = i return res
标签:blog val pre etc 记录 状态 code and question
原文地址:http://www.cnblogs.com/lettuan/p/6168435.html