LeetCode 283. Move Zeroes
2022.07.18
問題
https://leetcode.com/problems/move-zeroes/
typescript
/**
Do not return anything, modify nums in-place instead.
*/
function moveZeroes(nums: number[]): void {
const zero = nums.filter(n => n === 0).length
let cnt = 0
for (let i = 0; i < nums.length; i++) {
if (cnt > zero) break
if (nums[i] === 0) {
nums.splice(i, 1)
nums.push(0)
i--
cnt++
} else {
cnt = 0
}
}
};