leetcode First Missing Positive python

class Solution(object):
    def firstMissingPositive(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        intlen=len(nums)
        i=0
        while i < intlen:
            if nums[i] > 0 and nums[i] < intlen and nums[i] != nums[nums[i]-1]:
          #get the current num, and put it into it's right place
#for example : if get the third item is 5 ( index is 2, start with 0 ) , so the index of 5 should be 4 tmp
=nums[nums[i]-1] nums[nums[i]-1]=nums[i] nums[i]=tmp else: i+=1 for i in range(intlen): if nums[i] != i+1: return i+1 return intlen+1

 

posted @ 2015-12-21 22:58  hao.ma  阅读(144)  评论(0编辑  收藏  举报