Skip to content

Commit

Permalink
practice leetcode - reverse bits
Browse files Browse the repository at this point in the history
  • Loading branch information
vuquang23 committed Jan 18, 2025
1 parent 19e9019 commit 55fb7e2
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/practice/leetcode/reverse_bits/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/practice/leetcode/reverse_bits/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "reverse_bits"
version = "0.1.0"
edition = "2021"

[dependencies]
17 changes: 17 additions & 0 deletions src/practice/leetcode/reverse_bits/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// https://leetcode.com/problems/reverse-bits/

struct Solution;

impl Solution {
pub fn reverse_bits(x: u32) -> u32 {
let mut result: u32 = 0;
for i in 0..32 {
if (x >> i) & 1 == 1 {
result += 1 << (31 - i);
}
}
result
}
}

fn main() {}

0 comments on commit 55fb7e2

Please sign in to comment.