核心思想:两个游标
/*
* @lc app=leetcode id=80 lang=cpp
*
* [80] Remove Duplicates from Sorted Array II
*/
// @lc code=start
class Solution {
public:
int removeDuplicates(vector<int>& nums) {
int N = nums.size();
if(N<=0) return 0;
int L = 1;
int R = 1;
int cnt = 1;
int now = nums[0];
while(R<N){
if(nums[R] == now){
if(cnt >= 2){
R++;
continue;
}
cnt++;
}else{
now = nums[R];
cnt = 1;
}
nums[L++] = nums[R++];
}
return L;
}
};
// @lc code=end