Skip to content

Commit 631ba8e

Browse files
authored
Update 2380-time-needed-to-rearrange-a-binary-string.js
1 parent c23c35d commit 631ba8e

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

2380-time-needed-to-rearrange-a-binary-string.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,24 @@
1+
/**
2+
* @param {string} s
3+
* @return {number}
4+
*/
5+
const secondsToRemoveOccurrences = function(s) {
6+
let zeros = 0
7+
const n = s.length, { max } = Math
8+
let res = 0
9+
10+
for(let i = 0; i < n; i++) {
11+
if(s[i] === '0') zeros++
12+
if(s[i] === '1' && zeros > 0) {
13+
res = max(res + 1, zeros)
14+
}
15+
}
16+
return res
17+
};
18+
19+
// another
20+
21+
122
/**
223
* @param {string} s
324
* @return {number}

0 commit comments

Comments
 (0)