leetcode-华为专题-283. 移动零_leetcode

 

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