LeetCode | TwoSum
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了LeetCode | TwoSum相关的知识,希望对你有一定的参考价值。
def twoSum(self, nums, target): """ :type nums: List[int] :type target: int :rtype: List[int] """ dict = {} result = [] for i in range(len(nums)): dict[nums[i]]= i print(dict) for i in range(len(nums)): if (dict.get(target-nums[i]) != None) & (dict[target-nums[i]] != i ): print(i) result.append(i) result.append(dict.get(target-nums[i])) break return result
以上是关于LeetCode | TwoSum的主要内容,如果未能解决你的问题,请参考以下文章