We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 50b939c commit 2c89729Copy full SHA for 2c89729
solution/926. Flip String to Monotone Increasing/Solution.js
@@ -0,0 +1,17 @@
1
+const minFlipsMonoIncr = function (S) {
2
+ let n = S.length;
3
+ let f = [];
4
+ for (let i = 0; i < n + 1; i++) {
5
+ f.push(0);
6
+ }
7
+ for (let i = 0; i < n; i++) {
8
+ f[i + 1] = f[i] + (S[i] === '1');
9
10
+ let ans = n;
11
+ for (let i = 0; i <= n; i++) {
12
+ let a = f[i];
13
+ let b = (n - i) - (f[n] - f[i]);
14
+ ans = Math.min(ans, b + a);
15
16
+ return ans;
17
+};
0 commit comments