- 双指针
function removeDuplicates(nums: number[]): number {
const { length } = nums;
let fast = 2, slow = 2;
while (fast < length) {
// 只要不满足重复的条件,就可以往前排
if (nums[fast] !== nums[slow - 1] || nums[fast] !== nums[slow - 2]) {
nums[slow] = nums[fast];
slow++;
}
++fast;
}
return slow;
};