Участник:Polina Potapova/first-missing-positive

Материал из DISCOPAL
Перейти к: навигация, поиск

https://leetcode.com/problems/first-missing-positive

class Solution(object):
    def firstMissingPositive(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
 
        i=0
        lenght = len(nums)
        while i < lenght:
            if (0 < nums[i] <= lenght) and (nums[nums[i] - 1] != nums[i]):
                nums[nums[i] - 1], nums[i] = nums[i], nums[nums[i] - 1]
                i -= 1
            i += 1
 
        i = 0        
        while i < lenght:
            if nums[i] != (i + 1): return i + 1
            i += 1
        answer = lenght + 1
 
        return answer