1758. Minimum Changes To Make Alternating Binary String Easy

@problem@discussion
#String



1/**
2 * [1758] Minimum Changes To Make Alternating Binary String
3 *
4 * You are given a string s consisting only of the characters '0' and '1'. In one operation, you can change any '0' to '1' or vice versa.
5 * The string is called alternating if no two adjacent characters are equal. For example, the string "010" is alternating, while the string "0100" is not.
6 * Return the minimum number of operations needed to make s alternating.
7 *  
8 * Example 1:
9 * 
10 * Input: s = "0100"
11 * Output: 1
12 * Explanation: If you change the last character to '1', s will be "0101", which is alternating.
13 * 
14 * Example 2:
15 * 
16 * Input: s = "10"
17 * Output: 0
18 * Explanation: s is already alternating.
19 * 
20 * Example 3:
21 * 
22 * Input: s = "1111"
23 * Output: 2
24 * Explanation: You need two operations to reach "0101" or "1010".
25 * 
26 *  
27 * Constraints:
28 * 
29 * 	1 <= s.length <= 10^4
30 * 	s[i] is either '0' or '1'.
31 * 
32 */
33pub struct Solution {}
34
35// problem: https://leetcode.com/problems/minimum-changes-to-make-alternating-binary-string/
36// discuss: https://leetcode.com/problems/minimum-changes-to-make-alternating-binary-string/discuss/?currentPage=1&orderBy=most_votes&query=
37
38// submission codes start here
39
40impl Solution {
41    pub fn min_operations(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_1758() {
54    }
55}
56


Back
© 2025 bowen.ge All Rights Reserved.