Skip to content

Commit c6c5b8f

Browse files
authored
Update 926-flip-string-to-monotone-increasing.js
1 parent 3e65329 commit c6c5b8f

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

926-flip-string-to-monotone-increasing.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
1+
/**
2+
* @param {string} s
3+
* @return {number}
4+
*/
5+
const minFlipsMonoIncr = function(s) {
6+
const n = s.length
7+
let res = 0, oneCnt = 0
8+
for(const e of s) {
9+
if(e === '1') oneCnt++
10+
else {
11+
const stayZero = oneCnt
12+
const flipToOne = res + 1
13+
res = Math.min(stayZero, flipToOne)
14+
}
15+
}
16+
17+
return res
18+
};
19+
20+
// another
21+
22+
123
/**
224
* @param {string} s
325
* @return {number}

0 commit comments

Comments
 (0)