Javascript solution, if anyone is interested


  • 0
    P
    var moveZeroes = function(nums) {
        var temp = null;
        var j = 0;
        for(var i=0; i < nums.length; i++) {
            if (nums[i] !== 0) {
                temp = nums[j];
                nums[j] = nums[i];
                nums[i] = temp;
                j++;
            }
        }
    };

Log in to reply
 

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