Skip to content

Commit e09d4b7

Browse files
committed
Add LC 283 solution
1 parent 592b870 commit e09d4b7

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

283. Move Zeroes.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,24 @@ Constraints:
2121
Follow up: Could you minimize the total number of operations done?
2222
2323
*/
24+
25+
/**
26+
* @param {number[]} nums
27+
* @return {void} Do not return anything, modify nums in-place instead.
28+
*/
29+
const moveZeroes = (nums) => {
30+
let index = 0;
31+
32+
for (const num of nums) {
33+
if (num !== 0) {
34+
nums[index] = num;
35+
index++;
36+
}
37+
}
38+
39+
for (let i = index; i < nums.length; i++) {
40+
nums[i] = 0;
41+
}
42+
43+
return nums;
44+
};

0 commit comments

Comments
 (0)