Javascrip, solution-sharing, splice, push


  • 0
    C
    /**
     * @param {number[]} nums
     * @return {void} Do not return anything, modify nums in-place instead.
     */
    var moveZeroes = function(nums) {
        var length = nums.length;
        for(var i=0; i<length; i++){
            if(nums[i]===0){
                nums.splice(i, 1);
                nums.push(0);
                length--;
                i--;
            }
        }
    };

Log in to reply
 

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