class Solution(object): def twoSum(self, nums, target): dic = {} for i, num in enumerate(nums): if num in dic: return [dic[num], i] else: dic[target - num] = i x=Solution() l=[1,3,5,6] print(x.twoSum(l,9))
输出
[1, 3]
原文地址:https://www.cnblogs.com/sea-stream/p/10463703.html
时间: 2024-09-29 00:44:43