JS solution


  • 0
    S
    var moveZeroes = function(nums) {
        let zeroPos = 0
        nums.map((num) => {
            if(num != 0) {
                nums[zeroPos++] = num
            }
        })
        
        nums.map(() => {
            if(zeroPos < nums.length) {
                nums[zeroPos++] = 0
            }
        })
    };
    

Log in to reply
 

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