Simple Inplace Implementation in C++ O(N)


#1

if(A.size()==1){
return 1;
}
int curr=0;
for(int i=0;i<A.size()-1;i++){
if(A[i+1]!=A[i]){
curr++;
A[curr]=A[i+1];
}
}
A.erase(A.begin()+curr+1,A.end());
return A.size();


#2

Algo can be optimised a bit if u just remove erase statement. The test code will take care of that thing for which u have done this.