Why is this not working plzz help


#1

int Solution::removeDuplicates(vector &A) {

if(A.size()<2) return A.size();
vector<int> ans;
ans.push_back(A[0]);
for(int i=1;i<A.size();i++){
    while(A[i]==A[i-1]) i++;
    ans.push_back(A[i]);
}

for(int i=0;i<ans.size();i++){
    A[i] =ans[i];
 
}

return (ans.size());

}