My 20ms C++ solution


  • 6
    Z
     void moveZeroes(vector<int>& nums) {
        int i,count=0;
        for(i=0;i<nums.size();i++)
        {
            if(nums[i]==0)
            {
                ++count;
                continue;
            }
            nums[i-count]=nums[i];
        }
        for(i=nums.size()-1;i>nums.size()-1-count;i--)
        {
            nums[i]=0;
        }
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.