public class Solution {
public int removeDuplicates(int[] A) {
int count = 0;
int tmp = 0;
if(A == null || A.length == 0){
return 0;
}
if(A.length == 1){
return 1;
}
int pivot = A[0] - 1;
int compare = A[0];
for(int i = 1 ; i < A.length ; i++){
if(A[i] == compare){
if(tmp > 0){
A[i] = pivot;
count++;
}
tmp++;
}else{
compare = A[i];
//A[i - count] =A[i];
tmp = 0;
}
}
int index = 0;
for(int i = 0 ; i < A.length ; i++){
if(A[i] == pivot){
index++;
}else{
A[i - index] = A[i];
}
}
return A.length - count;
}
}
Remove Duplicates from Sorted Array II
最新推荐文章于 2020-02-08 17:36:31 发布