leetcode 热题100 两数之和
class Solution(object):
def twoSum(self, nums, target):
"""
:type nums: List[int]
:type target: int
:rtype: List[int]
"""
myDict = {}
for i,t in enumerate(nums):
myDict[nums[i]] = i
for i,t in enumerate(nums):
tmp = target - t
if myDict.get(tmp)!=None and myDict.get(tmp)!=i:
return [i,myDict.get(tmp)]
原文地址:https://blog.csdn.net/chenziang1/article/details/144408376
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!