Short Python solution

  • 0

    since the lenth of the array is L, the first missing number must be less than or equal to L+1.

    class Solution(object):
        def firstMissingPositive(self, nums):
            :type nums: List[int]
            :rtype: int
            if l==0: return 1
            count=[0 for i in range(l+2)]
            for i in range(len(nums)):
                if 0<=nums[i]<l+1:
            for i in range(1,l+2):
                if count[i]==0:return i
            return l+2

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.