Skip to content

Commit 79becca

Browse files
committed
feat: add rust solution to lc problem: No.0190
No.0190.Reverse Bits
1 parent f9781bf commit 79becca

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

solution/0100-0199/0190.Reverse Bits/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,21 @@ var reverseBits = function (n) {
121121
};
122122
```
123123

124+
### **Rust**
125+
126+
```rust
127+
impl Solution {
128+
pub fn reverse_bits(mut x: u32) -> u32 {
129+
let mut res = 0;
130+
for _ in 0..32 {
131+
res = (res << 1) | (x & 1);
132+
x >>= 1;
133+
}
134+
res
135+
}
136+
}
137+
```
138+
124139
### **...**
125140

126141
```

solution/0100-0199/0190.Reverse Bits/README_EN.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,21 @@ var reverseBits = function (n) {
106106
};
107107
```
108108

109+
### **Rust**
110+
111+
```rust
112+
impl Solution {
113+
pub fn reverse_bits(mut x: u32) -> u32 {
114+
let mut res = 0;
115+
for _ in 0..32 {
116+
res = (res << 1) | (x & 1);
117+
x >>= 1;
118+
}
119+
res
120+
}
121+
}
122+
```
123+
109124
### **...**
110125

111126
```
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
impl Solution {
2+
pub fn reverse_bits(mut x: u32) -> u32 {
3+
let mut res = 0;
4+
for _ in 0..32 {
5+
res = (res << 1) | (x & 1);
6+
x >>= 1;
7+
}
8+
res
9+
}
10+
}

0 commit comments

Comments
 (0)