Short and simple O(n) time O(1) space cpp solution


#1
int Solution::firstMissingPositive(vector<int> &A) {
int n = A.size();
if(!n) return 1;
for (int i = 0; i < n; i++)
    while(A[i] > 0 and A[i] <= n and A[A[i] - 1] !=  A[i])
        swap(A[A[i] - 1], A[i]);
        
for (int i = 0; i < n; i++)
    if (A[i] != i + 1)
        return i + 1;
return n + 1;
}