190. Reverse Bits Easy
1/**
2 * [190] Reverse Bits
3 *
4 * Reverse bits of a given 32 bits unsigned integer.
5 * Note:
6 *
7 * Note that in some languages, such as Java, there is no unsigned integer type. In this case, both input and output will be given as a signed integer type. They should not affect your implementation, as the integer's internal binary representation is the same, whether it is signed or unsigned.
8 * In Java, the compiler represents the signed integers using <a href="https://en.wikipedia.org/wiki/Two%27s_complement" target="_blank">2's complement notation</a>. Therefore, in Example 2 above, the input represents the signed integer -3 and the output represents the signed integer -1073741825.
9 *
10 *
11 * Example 1:
12 *
13 * Input: n = 00000010100101000001111010011100
14 * Output: 964176192 (00111001011110000010100101000000)
15 * Explanation: The input binary string 00000010100101000001111010011100 represents the unsigned integer 43261596, so return 964176192 which its binary representation is 00111001011110000010100101000000.
16 *
17 * Example 2:
18 *
19 * Input: n = 11111111111111111111111111111101
20 * Output: 3221225471 (10111111111111111111111111111111)
21 * Explanation: The input binary string 11111111111111111111111111111101 represents the unsigned integer 4294967293, so return 3221225471 which its binary representation is 10111111111111111111111111111111.
22 *
23 *
24 * Constraints:
25 *
26 * The input must be a binary string of length 32
27 *
28 *
29 * Follow up: If this function is called many times, how would you optimize it?
30 *
31 */
32pub struct Solution {}
33
34// problem: https://leetcode.com/problems/reverse-bits/
35// discuss: https://leetcode.com/problems/reverse-bits/discuss/?currentPage=1&orderBy=most_votes&query=
36
37// submission codes start here
38
39impl Solution {
40 pub fn reverse_bits(x: u32) -> u32 {
41 0
42 }
43}
44
45// submission codes end
46
47#[cfg(test)]
48mod tests {
49 use super::*;
50
51 #[test]
52 fn test_190() {
53 }
54}
55
Back
© 2025 bowen.ge All Rights Reserved.