Skip to content

Commit

Permalink
Merge pull request neetcode-gh#1379 from zim0369/rev-bits
Browse files Browse the repository at this point in the history
Create 190-Reverse-Bits.rs
  • Loading branch information
Ahmad-A0 authored Nov 2, 2022
2 parents 086c11f + d8a2b62 commit b2432a8
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions rust/190-Reverse-Bits.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
impl Solution {
pub fn reverse_bits(mut x: u32) -> u32 {
(0..32).fold(0, |mut res, _| {
res = (res << 1) | (x & 1);
x >>= 1;
res
})
}
}

0 comments on commit b2432a8

Please sign in to comment.