Simple CPP solution, have a look


#1

int Solution::removeDuplicates(vector &A) {
A.push_back(A.back()+1);
int p1=0,p2=1;
int count=1;
while(p2<A.size())
{
if(A[p2]!=A[p1])
{
count++;
p1=p2;
p2++;
}
else
{
while(A[p2]==A[p1])
p2++;
if((p2-p1)>=2)
{
p1+=2;
A.erase(A.begin()+p1,A.begin()+p2);
count++;
}
p1–;
p2=p1+1;
}
}
A.pop_back();
return --count;
}