My javascript s olution


  • 0
    I
    var moveZeroes = function(nums) {
        if(nums === null) {
            return;
        }
        var pNum = 0;
        var pZero = 0;
        while(pNum < nums.length && pZero < nums.length) {
            if(nums[pZero] !== 0){
                pZero++;
            } else if(nums[pNum] === 0 || pNum < pZero) {
                pNum++;
            } else if(pZero < pNum) {
                var aux =  nums[pNum];
                nums[pNum] = nums[pZero];
                nums[pZero] = aux;
                pZero++;
                pNum++;
            }
        }
    };
    

Log in to reply
 

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