Easy to understand solution using 2 pointers


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

}