题解 | #缺失的第一个正整数#

缺失的第一个正整数

http://www.nowcoder.com/practice/50ec6a5b0e4e45348544348278cdcee5

不借助额外的存储空间,不使用哈希表

# 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
#
# 
# @param nums int整型一维数组 
# @return int整型
#
class Solution:
    def minNumberDisappeared(self , nums: List[int]) -> int:
        # write code here
        nums.sort()
        index = 0
        for i in range(1, len(nums)):
            while nums[index] < i:
                index += 1
            if nums[index] > i:
                return i
            index += 1
        return nums[len(nums)-1] + 1

        
全部评论
真的笑了 排序的时间复杂度是多少? 在想什么呢
点赞
送花
回复
分享
发布于 2022-09-18 21:03 新加坡

相关推荐

点赞 评论 收藏
转发
点赞 收藏 评论
分享
牛客网
牛客企业服务