for Robot Artificial Inteligence

9. Move Zeros

|

class Solution {
public:
    void moveZeroes(vector<int>& nums) {
        int i=0;
        vector<int> Copy;
        for(int n : nums)
        {
            if(n!=0)
            {
                Copy.push_back(n);
            }
            else if(n==0)
            {
                i++;
            }
        }
        for(int a=0; a<i;a++)
        {
            Copy.push_back(0);
        }
        nums = Copy;
    }
};

Comments