Tianhe Gao

LC 283. Move Zeroes

 1/**
 2 * @param {number[]} nums
 3 * @return {void} Do not return anything, modify nums in-place instead.
 4 */
 5var moveZeroes = function (nums) {
 6  let len = nums.length
 7  let count = 0
 8  for (let i = 0; i < len; i++) {
 9    if (nums[i] !== 0) {
10      nums[count] = nums[i]
11      count++
12    }
13  }
14  for (let j = count; j < len; j++) {
15    nums[j] = 0
16  }
17  return nums
18};

No notes link to this note

Welcome to tell me your thoughts via "email"
UP