```
class Solution {
public:
int removeDuplicates(int A[], int n) {
if(n <= 0){
return n;
}
bool flag = false;
int pos =0;
for(int i=1;i<n;i++){
if(A[pos] != A[i]){
A[++pos] = A[i];
flag = false;
}else if(flag == false){
A[++pos] = A[i];
flag = true;
}
}
return pos+1;
}
};
```