Using STL simple solution

\int Solution::removeDuplicates(vector &A) {
int current=1,temp=A[0];
for(int i=1;i<A.size();i++){
if(A[i]!=temp){
A[current]=A[i];current++;temp=A[i];
}
}
A.erase(A.begin()+current,A.end());
return A.size();
}

A.erase(unique(A.begin(),A.end()),A.end());
    return A.size();
Click here to start solving coding interview questions