去除重复的元素,
只需对重复的元素进行覆盖即可,定义两个指针,i用于遍历,j用于覆盖只要a[i]!=a[j],说明元素不重复,i,j
同时++,否则,仅仅i++
public class Solution {
public int removeDuplicates(int[] A) {
int i = 1, j = 0;
if(A != null && A.length >= 1)
for( i = 1, j = 1; i < A.length; ++i){
if(A[i] != A[j - 1]){
A[j++] = A[i];
}
}
return j;
}
}