1.两数之和(Python实现)
思路:用字典记录下每个元素的位置

class Solution:
    def twoSum(self, nums, target):
        """
        :type nums: List[int]
        :type target: int
        :rtype: List[int]
        """
        dic={}
        for index,vaule in enumerate(nums):
            sub=target-vaule
            if sub in dic:
                return [dic[sub],index]
            else:
                dic[vaule]=index

相关文章:

  • 2022-12-23
  • 2021-10-05
  • 2022-12-23
  • 2021-11-25
  • 2021-11-21
  • 2022-02-09
猜你喜欢
  • 2021-11-27
  • 2022-12-23
  • 2021-04-12
  • 2021-09-26
  • 2022-01-08
  • 2022-12-23
  • 2021-08-26
相关资源
相似解决方案