public class Solution {
public int removeDuplicates(int[] A) {
// Start typing your Java solution below
// DO NOT write main() function
int len = A.length;
if(len==0)return 0;
if(len==1)return A[0];
int[] b = new int[len];
int count = 0;
int now = -1;
int t = 0;
for(int i = 0; i < len;i++){
if(now == A[i]){
if(count>=2)continue;
else{
b[t++]=now;count++;
}
}
else{
b[t++]=A[i];
count=1;
now = A[i];
}
}
for(int i = 0;i<t;i++)
A[i]=b[i];
return t;
}
}
Remove Duplicates from Sorted Array II
最新推荐文章于 2024-02-15 23:33:44 发布