class Solution {
public:
int removeDuplicates(int A[], int n) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
if(A==NULL||n<=0) {
return 0;
}
int index=0;
int pre=1;
bool dup=false;
while (index<n-1&&pre<=n-1) {
if (A[index]==A[pre]) {
if (!dup) {
//pre++;
A[++index]=A[pre];
pre++;
dup=true;
} else
// A[++index]=A[pre];
pre++;
}
else{
A[++index]=A[pre];
pre++;
dup=false;
}
}
return index+1;
}
};
public:
int removeDuplicates(int A[], int n) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
if(A==NULL||n<=0) {
return 0;
}
int index=0;
int pre=1;
bool dup=false;
while (index<n-1&&pre<=n-1) {
if (A[index]==A[pre]) {
if (!dup) {
//pre++;
A[++index]=A[pre];
pre++;
dup=true;
} else
// A[++index]=A[pre];
pre++;
}
else{
A[++index]=A[pre];
pre++;
dup=false;
}
}
return index+1;
}
};