Easy to understand and smallest soln in C++


#1

int Solution::removeDuplicates(vector &A) {
int len = A.size();
int count=0;
for(int i=0;i<len;i++){
int j=i;
while(j<len){
if(A[i]!=A[j]){
break;
}
j++;
}
if(j-i==1){
A[count]=A[i];
count++;
}else if(j-i>=2){
A[count]=A[i];
count++;
A[count]=A[i];
count++;
}
i=j-1;
}
return count;
}