Skip to content

Commit 7d0a242

Browse files
committed
feat: add rust solution to lc problem: No.2595
Signed-off-by: xiaolatiao <1628652790@qq.com>
1 parent b614297 commit 7d0a242

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

solution/2500-2599/2595.Number of Even and Odd Bits/README.md

+20
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,26 @@ function evenOddBit(n: number): number[] {
125125
}
126126
```
127127

128+
### **Rust**
129+
130+
```rust
131+
impl Solution {
132+
pub fn even_odd_bit(mut n: i32) -> Vec<i32> {
133+
let mut answer = vec![0; 2];
134+
135+
let mut i = 0;
136+
while n != 0 {
137+
answer[i] += n & 1;
138+
139+
n >>= 1;
140+
i ^= 1;
141+
}
142+
143+
answer
144+
}
145+
}
146+
```
147+
128148
### **...**
129149

130150
```

solution/2500-2599/2595.Number of Even and Odd Bits/README_EN.md

+20
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,26 @@ function evenOddBit(n: number): number[] {
117117
}
118118
```
119119

120+
### **Rust**
121+
122+
```rust
123+
impl Solution {
124+
pub fn even_odd_bit(mut n: i32) -> Vec<i32> {
125+
let mut answer = vec![0; 2];
126+
127+
let mut i = 0;
128+
while n != 0 {
129+
answer[i] += n & 1;
130+
131+
n >>= 1;
132+
i ^= 1;
133+
}
134+
135+
answer
136+
}
137+
}
138+
```
139+
120140
### **...**
121141

122142
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
impl Solution {
2+
pub fn even_odd_bit(mut n: i32) -> Vec<i32> {
3+
let mut answer = vec![0; 2];
4+
5+
let mut i = 0;
6+
while n != 0 {
7+
answer[i] += n & 1;
8+
9+
n >>= 1;
10+
i ^= 1;
11+
}
12+
13+
answer
14+
}
15+
}

0 commit comments

Comments
 (0)