缺失的第一个正数【哈希】

发布时间:2024年01月07日

Problem: 41. 缺失的第一个正数

思路 & 解题方法

哈希

复杂度

时间复杂度:

添加时间复杂度, 示例: O ( n ) O(n) O(n)

空间复杂度:

添加空间复杂度, 示例: O ( n ) O(n) O(n)

Code

class Solution:
    def firstMissingPositive(self, nums: List[int]) -> int:
        length = len(nums)
        hashTable = collections.defaultdict(int)
        for x in nums:
            hashTable[x] += 1
        for i in range(1, length + 5):
            if i not in hashTable:
                return i
文章来源:https://blog.csdn.net/qq_45985728/article/details/135437550
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。