水题。
class Solution {
public:
int removeDuplicates(vector<int>& nums) {
if (nums.empty()) {
return 0;
}
int ret = 1;
int eq_cnt = 1;
int pre_num = nums[0];
int num_cnt = nums.size();
for (int i = 1; i < num_cnt; i++) {
if (nums[i] == pre_num) {
eq_cnt++;
if (eq_cnt > 2) {
continue;
} else {
nums[ret] = nums[i];
ret++;
continue;
}
} else {
pre_num = nums[i];
nums[ret] = nums[i];
ret++;
eq_cnt = 1;
}
}
return ret;
}
};