2914. Minimum Number of Changes to Make Binary String Beautiful Medium

@problem@discussion
#String



1/**
2 * [2914] Minimum Number of Changes to Make Binary String Beautiful
3 *
4 * You are given a 0-indexed binary string s having an even length.
5 * A string is beautiful if it's possible to partition it into one or more substrings such that:
6 * 
7 * 	Each substring has an even length.
8 * 	Each substring contains only 1's or only 0's.
9 * 
10 * You can change any character in s to 0 or 1.
11 * Return the minimum number of changes required to make the string s beautiful.
12 *  
13 * <strong class="example">Example 1:
14 * 
15 * Input: s = "1001"
16 * Output: 2
17 * Explanation: We change s[1] to 1 and s[3] to 0 to get string "1100".
18 * It can be seen that the string "1100" is beautiful because we can partition it into "11|00".
19 * It can be proven that 2 is the minimum number of changes needed to make the string beautiful.
20 * 
21 * <strong class="example">Example 2:
22 * 
23 * Input: s = "10"
24 * Output: 1
25 * Explanation: We change s[1] to 1 to get string "11".
26 * It can be seen that the string "11" is beautiful because we can partition it into "11".
27 * It can be proven that 1 is the minimum number of changes needed to make the string beautiful.
28 * 
29 * <strong class="example">Example 3:
30 * 
31 * Input: s = "0000"
32 * Output: 0
33 * Explanation: We don't need to make any changes as the string "0000" is beautiful already.
34 * 
35 *  
36 * Constraints:
37 * 
38 * 	2 <= s.length <= 10^5
39 * 	s has an even length.
40 * 	s[i] is either '0' or '1'.
41 * 
42 */
43pub struct Solution {}
44
45// problem: https://leetcode.com/problems/minimum-number-of-changes-to-make-binary-string-beautiful/
46// discuss: https://leetcode.com/problems/minimum-number-of-changes-to-make-binary-string-beautiful/discuss/?currentPage=1&orderBy=most_votes&query=
47
48// submission codes start here
49
50impl Solution {
51    pub fn min_changes(s: String) -> i32 {
52        0
53    }
54}
55
56// submission codes end
57
58#[cfg(test)]
59mod tests {
60    use super::*;
61
62    #[test]
63    fn test_2914() {
64    }
65}
66


Back
© 2025 bowen.ge All Rights Reserved.