题目
题目链接
题解
class Solution {
public int removeDuplicates(int[] nums) {
if (nums == null || nums.length == 0) {
return 0;
}
if (nums.length == 1) {
return 1;
}
int n = nums.length;
// sp前指针 i后指针
int sp = 0;
for (int i = 1; i < n; i++) {
if (nums[i] != nums[i - 1]) {
// 数据前移,sp指针后移
nums[sp + 1] = nums[i];
sp++;
}
}
return sp + 1;
}
}