标签:
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
leetcode First Missing Positive python
标签:
原文地址:http://www.cnblogs.com/allenhaozi/p/5065194.html