C++ 2 lines concise solution


  • 0
    H
        void moveZeroes(vector<int>& nums) {
            int index = 0;
            for(int i = 0; i < nums.size(); i++) if(nums[i] != 0) swap(nums[i], nums[index++]);
        }
    

Log in to reply
 

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