class Solution {
public:
int removeDuplicates(vector<int>& nums) {
if (nums.empty()) return 0;
int ret = 1;
vector<int> v(nums.size());
int count = 1;
v[0] = nums[0];
for(int i = 1; i < nums.size(); i++) {
if (nums[i] == nums[i-1]) {
count++;
} else {
count = 1;
}
if (count <= 2) {
v[ret++] = nums[i];
}
}
for(int i = 0; i < ret; i++) {
nums[i] = v[i];
}
return ret;
}
};