Javascript easy but not so efficient solution


  • 0
    A
    var moveZeroes = function(nums) {
    var len = nums.length;
    for(var i = 0; i<len; i++){
        if(nums[i] === 0){
            nums.splice(i,1);
            i--;
        }
    }
    var currLen = nums.length;
    for(i = 0; i<len-currLen;i++){
        nums.push(0);
     } 
    };

Log in to reply
 

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