```
class Solution {
public:
int removeDuplicates(vector<int>& nums) {
if(nums.size()==0) return 0;
int j=0;
for(int i=0;i<nums.size();i++)
{
int num=1;
while(nums[i]==nums[i+1])
{
num++;
i++;
}
if(num>=2)
{
nums[j++]=nums[i];
nums[j++]=nums[i];
}
else
nums[j++]=nums[i];
}
return j;
}
};
```

only one test cannot succeed.

input:[0,0,1,1,2,3,4]

results is right, but when I submit, the output is [0,0,1,1,2,3,4,4] wrong.

Someone say it may be undefined behaviour, but I tried on Ideone.com，also succeed.

Thank you!