Open github-actions[bot] opened 2 years ago
/*
* @lc app=leetcode id=283 lang=typescript
*
* [283] Move Zeroes
*/
// @lc code=start
/**
Do not return anything, modify nums in-place instead.
*/
function moveZeroes(nums: number[]): void {
let pointerA = 0;
for (let pointerB = 0; pointerB < nums.length; pointerB++) {
// if nums[pointerB] not equals to zero, then swap nums[pointerA] and nums[pointerB]
// and increase both pointerA and pointerB
// if nums[pointerB] equals to zero, then do nothing about pointerA
// and increase pointerB
// make sure pointerA always point to the leftmost zero
if (nums[pointerB]) {
pointerA !== pointerB && ([nums[pointerA], nums[pointerB]] = [nums[pointerB], nums[pointerA]]);
pointerA++;
}
}
};
// @lc code=end
Nickname: Geeku From vscode-hzfe-algorithms
283. Move Zeroes