926. Flip String to Monotone Increasing Medium
1/**
2 * [926] Flip String to Monotone Increasing
3 *
4 * A binary string is monotone increasing if it consists of some number of 0's (possibly none), followed by some number of 1's (also possibly none).
5 * You are given a binary string s. You can flip s[i] changing it from 0 to 1 or from 1 to 0.
6 * Return the minimum number of flips to make s monotone increasing.
7 *
8 * Example 1:
9 *
10 * Input: s = "00110"
11 * Output: 1
12 * Explanation: We flip the last digit to get 00111.
13 *
14 * Example 2:
15 *
16 * Input: s = "010110"
17 * Output: 2
18 * Explanation: We flip to get 011111, or alternatively 000111.
19 *
20 * Example 3:
21 *
22 * Input: s = "00011000"
23 * Output: 2
24 * Explanation: We flip to get 00000000.
25 *
26 *
27 * Constraints:
28 *
29 * 1 <= s.length <= 10^5
30 * s[i] is either '0' or '1'.
31 *
32 */
33pub struct Solution {}
34
35// problem: https://leetcode.com/problems/flip-string-to-monotone-increasing/
36// discuss: https://leetcode.com/problems/flip-string-to-monotone-increasing/discuss/?currentPage=1&orderBy=most_votes&query=
37
38// submission codes start here
39
40impl Solution {
41 pub fn min_flips_mono_incr(s: String) -> i32 {
42 0
43 }
44}
45
46// submission codes end
47
48#[cfg(test)]
49mod tests {
50 use super::*;
51
52 #[test]
53 fn test_926() {
54 }
55}
56
Back
© 2025 bowen.ge All Rights Reserved.