码迷,mamicode.com
首页 > 其他好文 > 详细

Leetcode 41 First Missing Positive

时间:2015-06-23 17:50:39      阅读:100      评论:0      收藏:0      [点我收藏+]

标签:


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


Leetcode 41 First Missing Positive

标签:

原文地址:http://blog.csdn.net/andrew9tech/article/details/46608015

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!