Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

moves zeroes

var moveZeroes = function (nums) {
    const totalLength = nums.length-1;
    for (let index = totalLength; index >=0 ; index--) {
        let element = nums[index];
        if (element === 0) {
            nums.push(nums.splice(index,1)[0]);
        }
    }
    return nums;
};
Source by leetcode.com #
 
PREVIOUS NEXT
Tagged: #moves #zeroes
ADD COMMENT
Topic
Name
5+5 =