First missing Positive in Python Simple Steps


  • 0
    V
    class Solution(object):
        def firstMissingPositive(self, nums):
            """
            :type nums: List[int]
            :rtype: int
            """
            if len(nums)>0:
                maxi = max(nums)
                if maxi>0:
                    for i in range(0,maxi):
                        if i in nums:
                            continue
                        elif i>0:
                            return i
                    else:
                        return maxi+1
                if maxi <= 0:
                    return 1
            else:
                return 1
    

Log in to reply
 

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