llllmz

导航

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;
    }
};

 

posted on 2024-09-08 16:28  神奇的萝卜丝  阅读(21)  评论(0)    收藏  举报