Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions reverse-bits/DaleSeo.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// TC: O(1)
// SC: O(1)
impl Solution {
pub fn reverse_bits(n: i32) -> i32 {
let mut result = 0u32;
let mut num = n as u32;

for i in 0..32 {
// Extract the least significant bit
let bit = num & 1;
// Place it in the reversed position
result |= bit << (31 - i);
// Shift num right to process the next bit
num >>= 1;
}

result as i32
}
}