My simple Javascript solution


  • 1
    K
    var moveZeroes = function(nums) {
    //[0, 1, 0, 3, 12]
    var len=nums.length;
    for(var i=0; i<len;)
    {
        if(nums[i]=== 0){
            nums.splice(i, 1);
            nums.push(0);
            len--;
        }
        else i++;
    }
    };

Log in to reply
 

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