Skip to content

Commit 4c281f9

Browse files
authored
Create 1089-duplicate-zeros.js
1 parent b887f16 commit 4c281f9

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

1089-duplicate-zeros.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* @param {number[]} arr
3+
* @return {void} Do not return anything, modify arr in-place instead.
4+
*/
5+
const duplicateZeros = function(arr) {
6+
const len = arr.length
7+
for (let i = len - 1; i >= 0; i--) {
8+
if (arr[i] === 0) arr.splice(i, 0, 0)
9+
}
10+
while (arr.length > len) {
11+
arr.pop()
12+
}
13+
}

0 commit comments

Comments
 (0)