```
class Solution {
public:
int removeDuplicates(vector<int>& nums) {
if (nums.size() == 0) return 0;
int i = 1;
while (i < nums.size()) {
if (nums[i] == nums[i - 1]) i++;
while (nums[i] == nums[i - 1] && i < nums.size()) nums.erase(nums.begin() + i);
i++;
}
return nums.size();
}
};
```