My JS solution (144ms)


  • 1
    V
    var moveZeroes = function(nums) {
        var endIdx = nums.length;
        for(var idx = 0; idx < endIdx; idx++){
            while(nums[idx] === 0 && idx < endIdx){
                nums.splice(idx, 1);
                nums.push(0);
                endIdx--;
            }
        }
    };

Log in to reply
 

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