Skip to content

Commit 280a4b6

Browse files
authored
feat: add rust solution to lc problem: No.3304 (#4542)
No.3304.Find the K-th Character in String Game I
1 parent 11b9cba commit 280a4b6

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

solution/3300-3399/3304.Find the K-th Character in String Game I/README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,23 @@ function kthCharacter(k: number): string {
163163
}
164164
```
165165

166+
#### Rust
167+
168+
```rust
169+
impl Solution {
170+
pub fn kth_character(k: i32) -> char {
171+
let mut word = vec![0];
172+
while word.len() < k as usize {
173+
let m = word.len();
174+
for i in 0..m {
175+
word.push((word[i] + 1) % 26);
176+
}
177+
}
178+
(b'a' + word[(k - 1) as usize] as u8) as char
179+
}
180+
}
181+
```
182+
166183
<!-- tabs:end -->
167184

168185
<!-- solution:end -->

solution/3300-3399/3304.Find the K-th Character in String Game I/README_EN.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,23 @@ function kthCharacter(k: number): string {
161161
}
162162
```
163163

164+
#### Rust
165+
166+
```rust
167+
impl Solution {
168+
pub fn kth_character(k: i32) -> char {
169+
let mut word = vec![0];
170+
while word.len() < k as usize {
171+
let m = word.len();
172+
for i in 0..m {
173+
word.push((word[i] + 1) % 26);
174+
}
175+
}
176+
(b'a' + word[(k - 1) as usize] as u8) as char
177+
}
178+
}
179+
```
180+
164181
<!-- tabs:end -->
165182

166183
<!-- solution:end -->
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
impl Solution {
2+
pub fn kth_character(k: i32) -> char {
3+
let mut word = vec![0];
4+
while word.len() < k as usize {
5+
let m = word.len();
6+
for i in 0..m {
7+
word.push((word[i] + 1) % 26);
8+
}
9+
}
10+
(b'a' + word[(k - 1) as usize] as u8) as char
11+
}
12+
}

0 commit comments

Comments
 (0)