其他分享
首页 > 其他分享> > 查找表_leetcode1

查找表_leetcode1

作者:互联网

#coding=utf-8
# 解题思路:查找表 适合只有唯一解的情况 20190302 找工作期间

class Solution(object):
def twoSum(self, nums, target):
"""
:type nums: List[int]
:type target: int
:rtype: List[int]
"""

dic = {}
for i, num in enumerate(nums):
if num in dic:
return [dic[num], i]
else: dic[target - num] = i

标签:num,target,nums,int,leetcode1,dic,查找,type
来源: https://www.cnblogs.com/lux-ace/p/10546889.html