Simple python code


  • -1
    M
    class Solution(object):
        def firstMissingPositive(self, nums):
            """
            :type nums: List[int]
            :rtype: int
            """
            nums = list(set(nums))
            nums.sort()
            now = 0
            for i in range(len(nums)):
                if nums[i]>0:
                    if nums[i]!= now+1:
                        return now+1
                    else:
                        now = now+1
            
            if now==0:
                return 1
            
            return now+1
                    
    

Log in to reply
 

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