class Solution {
public:
void moveZeroes(vector<int>& nums) {
int count = 0;
for(vector<int>::iterator it = nums.begin();it!=nums.end();++it)
{
if(*it == 0)
count++;
else
*(it-count) = *it;
}
for(vector<int>::reverse_iterator it = nums.rbegin();count != 0;it++,count--)
{
*it = 0;
}
}
};
LeetCode 283. Move Zeroes
最新推荐文章于 2024-09-01 11:29:54 发布