class Solution {
public:
int removeDuplicates(int A[], int n) {
if(n<=1)
return n;
int j=1;
int value=A[0];
int count=1;
for(int i=1;i<n;i++)
{
if(A[i]==value)
{
count++;
if(count<=2)
{
A[j]=A[i];
j++;
}
}
else
{
count=1;
value=A[i];
A[j++]=A[i];
}
}
return j;
}
};
Remove Duplicates from Sorted Array II
最新推荐文章于 2020-02-08 17:36:31 发布