通过前后交换查找重复的数字

即判断A[i]是否等于i
**41. First Missing Positive **
Given an unsorted integer array, find the first missing positive integer.

For example,
Given [1,2,0] return 3,
and [3,4,-1,1] return 2.

Your algorithm should run in O(n) time and uses constant space.
代码如下:

class Solution {
public:
    int firstMissingPositive(vector& nums) {
        int n = nums.size();
        if(n==0)
          return 1;
        
        for(int i=0;i0&&nums[i]

你可能感兴趣的:(通过前后交换查找重复的数字)