LeetCode 刷题记录

Posted WESWES

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了LeetCode 刷题记录相关的知识,希望对你有一定的参考价值。

 

1 两数之和(题目链接

class Solution:                # 一次哈希法
    def twoSum(self, nums, target):
        """
        :type nums: List[int]
        :type target: int
        :rtype: List[int]
        """
        m = {}                              
        for i in range(len(nums)):
            minus = target - nums[i] 
            if minus in m and i != m[minus]:
                return [i, m[minus]]
            m[nums[i]] = i
        return None

 

以上是关于LeetCode 刷题记录的主要内容,如果未能解决你的问题,请参考以下文章