分析:文章指出所用的算法负载度
class Solution(object): def firstMissingPositive(self, nums): """ :type nums: List[int] :rtype: int """ nums = list(set(nums)) if nums == []: return 1 for i,num in enumerate(nums): if num < 0 or num> len(nums): nums[i] = 0 for i in range(len(nums)): while (nums[i] != i+1) and (nums[i] > 0): #如果 a = nums[nums[i]-1] nums[nums[i]-1] = nums[i]# nums[i] = a for i,num in enumerate(nums): if num == 0: return i+1 elif i == len(nums)-1: return num+1 a = Solution() a.firstMissingPositive([])