latched之First Missing Positive

来源:互联网 发布:windows xp wifi支持 编辑:程序博客网 时间:2024/06/05 00:30

这道题一方面是没有排序过,一方面是有可能有重复的。本次采用了跟上个missing number不一样的判断。代码如下:

class Solution(object):    def firstMissingPositive(self, nums):        """        :type nums: List[int]        :rtype: int        """        for i in range(1, len(nums) + 1):            if i not in nums:                return i        else:            return len(nums) + 1


0 0
原创粉丝点击