Simple C++ Solution does'nt exist!


#1
void Solution::sortColors(vector<int> &A) {
    int pos = 0, n = A.size();
    for (int i = 0; i < n; i++) {
        if (A[i] == 0) {
            swap(A[i], A[pos++]);
        }
    }
    pos = n - 1;
    for (int i = n - 1; i >= 0; i--) {
        if (A[i] == 2) {
            swap(A[i], A[pos--]);
        }
    }
}

#2

A suggestion: In the second loop I guess you need not go up to zero since if there are zeros they are already sorted. I think i>=pos could be the condition And use another variable for storing n-1.