We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent a260422 commit 1f42a10Copy full SHA for 1f42a10
String/926.md
@@ -0,0 +1,30 @@
1
+## Flip String to Monotone Increasing
2
+
3
+#### Description
4
5
+[link](https://leetcode.com/problems/flip-string-to-monotone-increasing/discuss/184080/Python-3-liner)
6
7
+---
8
9
+#### Solution
10
11
+- We start with assuming "111.." section occupies all string, s.
12
+- Then we update "000.." section as s[:i + 1] and "111.." section as s[i + 1:] during iteration as well as the result
13
+- "zeros" variable counts all misplaced "0"s and "ones" variable counts all misplaced "1"s
14
15
16
17
+#### Code
18
19
+O(n)
20
21
+```python
22
+class Solution:
23
+ def minFlipsMonoIncr(self, s: str) -> int:
24
+ ones = 0
25
+ res = zeros = s.count("0")
26
+ for c in s:
27
+ ones, zeros = (ones + 1, zeros) if c == "1" else (ones, zeros - 1)
28
+ res = min(res, ones + zeros)
29
+ return res
30
+```
0 commit comments