您的位置:首页 > 其它

80 Remove Duplicates from Sorted Array ii

2015-05-28 10:04 225 查看
public int removeDuplicates(int[] A) {
if(A==null || A.length==0)
return 0;
int idx = 0;
int count = 0;
for(int i=0;i<A.length;i++)
{
if(i>0 && A[i]==A[i-1])
{
count++;
if(count>=2)
continue;
}
else
{
count = 1;
}
A[idx++]=A[i];
}
return idx;
}


与remove duplicates from sorted array i相似,本题维持一个count, >=2时候就跳过。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: