LeetCode:283.移动0

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

你可能感兴趣的:(LeetCode)