We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents b24402a + e1adcc7 commit 77b83f7Copy full SHA for 77b83f7
reverse-bits/DaleSeo.rs
@@ -0,0 +1,19 @@
1
+// TC: O(1)
2
+// SC: O(1)
3
+impl Solution {
4
+ pub fn reverse_bits(n: i32) -> i32 {
5
+ let mut result = 0u32;
6
+ let mut num = n as u32;
7
+
8
+ for i in 0..32 {
9
+ // Extract the least significant bit
10
+ let bit = num & 1;
11
+ // Place it in the reversed position
12
+ result |= bit << (31 - i);
13
+ // Shift num right to process the next bit
14
+ num >>= 1;
15
+ }
16
17
+ result as i32
18
19
+}
0 commit comments