leetcode 283. Move Zeroes

一次遍历就可以

class Solution {
public:
    void moveZeroes(vector<int>& nums) {
        int length = nums.size();
        if(length <= 0)
            return;
        int j = 0;
        for(int i = 0;i < length;i++){
            if(nums[i] != 0){
                if(i != j){
                    nums[j] = nums[i];
                    nums[i] = 0;
                }
                j++;
            }
        }
        return;
    }
};

https://www.cnblogs.com/wingyip/archive/2016/05/18/5507089.html

原文地址:https://www.cnblogs.com/ymjyqsx/p/9652376.html