Leetcode 41 First Missing Positive

来源:互联网 发布:mysql distinct 编辑:程序博客网 时间:2024/05/05 09:55


class Solution:    # @param {integer[]} nums    # @return {integer}    def firstMissingPositive(self, nums):        Length = len(nums)        for i in range(Length):            while nums[i] != i+1:                if nums[i] <= 0 or nums[i] > Length or nums[i] == nums[nums[i]-1]:                    break                temp = nums[nums[i]-1]; nums[nums[i]-1] = nums[i]; nums[i] = temp        for j in range(Length):            if nums[j] != j+1:                return j+1        return Length+1


0 0