leetcode 26. 删除有序数组中的重复项
直接法
public int removeDuplicates(int[] nums) {
if (nums == null) {
return -1;
}
boolean start = false;
int nextIndex = 1;
for (int i = 1; i < nums.length; i++) {
if (nums[i] != nums[i - 1]) {
if (!start) {
continue;
} else {
nums[nextIndex++] = nums[i];
}
} else {
if (!start) {
nextIndex = i;
start = true;
}
}
}
return start ? nextIndex : nums.length;
}