两数相加最优解
class Solution:def twoSum(self,nums, target):“”":type nums: List[int]:type target: int:rtype: List[int]“”"#用len()方法取得nums列表长度n = len(nums)#创建一个空字典d = {}for x in range(n):a = target - nums[x]#字典d中存在nums[x]时if nums[x] in d:return d[nums[x]],x
复制链接