283. 移动零

class Solution {
public:
void moveZeroes(vector<int>& nums) {
int head = 0, curIndex = 0;
for(; curIndex < nums.size(); ++curIndex){
if(nums[curIndex] != 0) nums[head++] = nums[curIndex];
}
for(; head < nums.size(); ++head) nums[head] = 0;
}
};

浙公网安备 33010602011771号