感觉比较简单,不过一开始居然看错题目,自己写了一个排序算法。
public class Solution {
public int removeDuplicates(int[] A) {
if (A == null || A.length == 0) {
return 0;
}
int firstIndex = 0;
for (int secondIndex = 1; secondIndex < A.length; ++secondIndex) {
if (A[secondIndex] != A[firstIndex]) {
A[++firstIndex] = A[secondIndex];
}
}
return firstIndex + 1;
}
}