LC 283. Move Zeroes

/**
 * @param {number[]} nums
 * @return {void} Do not return anything, modify nums in-place instead.
 */
var moveZeroes = function (nums) {
  let len = nums.length
  let count = 0
  for (let i = 0; i < len; i++) {
    if (nums[i] !== 0) {
      nums[count] = nums[i]
      count++
    }
  }
  for (let j = count; j < len; j++) {
    nums[j] = 0
  }
  return nums
};
欢迎通过「邮件」或者点击「这里」告诉我你的想法
Welcome to tell me your thoughts via "email" or click "here"