class Solution {
public:
int removeDuplicates(vector<int>& nums) {
int n = nums.size();
if(n <= 2) return n;
int i = 2;
for(int j = 2; j < n; j ++)
if(nums[j] != nums[i - 2]){
nums[i] = nums[j];
i ++; //如果不等于,i和j是同时加的,即下一轮ij相等
//如果等的话,略过j这个元素
}
return i;
}
};