题目可以自行百度。我有空就加上题目
class Solution(object):
def twoSum(self, nums, target):
d = {}
for i, num in enumerate(nums):
if target-num in d:
return [d[target-num], i]
d[num] = i
if __name__ == '__main__':
nums = [2, 7, 11, 15]
target = 9
a = Solution()
c = a.twoSum(nums, target)
print(c)