LC 283. Move Zeroes

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
/**
 * @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
};





评论和交流请发送邮件到 me@tianhegao.com





通过以下渠道赞赏此文