public int removeDuplicates(int[] A) {
// Start typing your Java solution below
// DO NOT write main() function
if(A == null || A.length == 0){
return 0;
}
if(A.length == 1){
return 1;
}
int dup = A[0];
int length = A.length;
int count = 0;
int start = 1;
while(start < length - count){
if(A[start] == dup){
for(int j = start; j < length - 1 - count; j++){
A[j] = A[j+1];
}
count++;
continue;
}else{
dup = A[start];
start++;
}
}
return length - count;
}
Remove Duplicates from Sorted Array
最新推荐文章于 2013-05-19 16:05:26 发布