class Solution {
public int removeDuplicates(int[] nums) {
if (nums.length == 0) {
return 0;
}
// 初始化快慢指针
int slow = 0;
int fast = 0;
while (fast < nums.length) {
if (nums[fast] != nums[slow]) {
slow++;
}
// 给新的无重复元素的数组赋值 赋值范围[0, slow]
nums[slow] =nums[fast];
fast++;
}
// 数组长度为最后一个元素下标 + 1
return slow + 1;
}
}