3750. Minimum Number of Flips to Reverse Binary String Easy

@problem@discussion
#Math#Two Pointers#String#Bit Manipulation



1/**
2 * [3750] Minimum Number of Flips to Reverse Binary String
3 *
4 * You are given a positive integer n.
5 * Let s be the binary representation of n without leading zeros.
6 * The reverse of a binary string s is obtained by writing the characters of s in the opposite order.
7 * You may flip any bit in s (change 0 → 1 or 1 → 0). Each flip affects exactly one bit.
8 * Return the minimum number of flips required to make s equal to the reverse of its original form.
9 *  
10 * <strong class="example">Example 1:
11 * <div class="example-block">
12 * Input: <span class="example-io">n = 7</span>
13 * Output: <span class="example-io">0</span>
14 * Explanation:
15 * The binary representation of 7 is "111". Its reverse is also "111", which is the same. Hence, no flips are needed.
16 * </div>
17 * <strong class="example">Example 2:
18 * <div class="example-block">
19 * Input: <span class="example-io">n = 10</span>
20 * Output: <span class="example-io">4</span>
21 * Explanation:
22 * The binary representation of 10 is "1010". Its reverse is "0101". All four bits must be flipped to make them equal. Thus, the minimum number of flips required is 4.
23 * </div>
24 *  
25 * Constraints:
26 * 
27 * 	1 <= n <= 10^9
28 * 
29 */
30pub struct Solution {}
31
32// problem: https://leetcode.com/problems/minimum-number-of-flips-to-reverse-binary-string/
33// discuss: https://leetcode.com/problems/minimum-number-of-flips-to-reverse-binary-string/discuss/?currentPage=1&orderBy=most_votes&query=
34
35// submission codes start here
36
37impl Solution {
38    pub fn minimum_flips(n: i32) -> i32 {
39        0
40    }
41}
42
43// submission codes end
44
45#[cfg(test)]
46mod tests {
47    use super::*;
48
49    #[test]
50    fn test_3750() {
51    }
52}
53

Back
© 2026 bowen.ge All Rights Reserved.