Skip to content

Commit 6ece05d

Browse files
authored
reverse bits solution without explicit u32 cast
1 parent bfb5219 commit 6ece05d

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

reverse-bits/yhkee0404.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ static _TABLE: OnceLock<Vec<i32>> = OnceLock::new();
55
impl Solution {
66

77
pub fn reverse_bits(mut n: i32) -> i32 {
8-
let mut x: u32 = 0;
8+
let mut x = 0;
99
for i in 0..6 {
10-
let shift = if i == 5 {2} else {6} as u32;
11-
x = x << shift | Self::init_table()[(n & (1 << shift) - 1) as usize] as u32 >> 6 - shift;
10+
let shift = if i == 5 {2} else {6};
11+
x = x << shift | Self::init_table()[(n & (1 << shift) - 1) as usize] >> 6 - shift;
1212
n >>= 6;
1313
}
1414
x as i32

0 commit comments

Comments
 (0)