Javascript Solution, O(N)


  • 0
    var moveZeroes = function(nums) {
        var count = 0;
        // Iterate and get all non zero entities
        for (var i=0; i<nums.length; i++) {
            if (nums[i] !== 0) {
                nums[count++] = nums[i];
            }
        }
        while (count < nums.length) {
            nums[count++] = 0;
        }
    };
    

Log in to reply
 

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