public class Solution {
public int removeDuplicates(int[] A) {
if (A.length==0) return 0;
if (A.length==1) return 1;
int p=0;
int q=1;
while (p<A.length && q<A.length) {
if (A[q]==A[p]) q++;
else {
p++;
A[p] = A[q];
q++;
}
}
return p+1;
}
}
1. Two pointers;
回复删除2. 如果A[q]!=A[p],q++.
3. 找到第一个A[q]!=A[p],令A[p+1]=A[q].
更正:
回复删除2. 如果A[q]==A[p], q++.