class Solution {
public:
int firstMissingPositive(vector<int>& nums) {
int n=nums.size();
for(int i=0;i<n;i++)
{
while(nums[i]>0&&nums[i]<=n&&nums[i]!=nums[nums[i]-1])
//如果nums[i]应该存放的位置放的不是nums[i]
swap(nums[i],nums[nums[i]-1]);
}
for(int i=0;i<n;i++)
if(nums[i]!=i+1) return i+1;
return n+1;
}
};
标签:nums,int,i0,41,正数,缺失
From: https://www.cnblogs.com/tangxibomb/p/17247830.html