diff --git a/solution/3300-3399/3304.Find the K-th Character in String Game I/README.md b/solution/3300-3399/3304.Find the K-th Character in String Game I/README.md index 1fd83b1df8404..c4db9a151e8db 100644 --- a/solution/3300-3399/3304.Find the K-th Character in String Game I/README.md +++ b/solution/3300-3399/3304.Find the K-th Character in String Game I/README.md @@ -163,6 +163,23 @@ function kthCharacter(k: number): string { } ``` +#### Rust + +```rust +impl Solution { + pub fn kth_character(k: i32) -> char { + let mut word = vec![0]; + while word.len() < k as usize { + let m = word.len(); + for i in 0..m { + word.push((word[i] + 1) % 26); + } + } + (b'a' + word[(k - 1) as usize] as u8) as char + } +} +``` + diff --git a/solution/3300-3399/3304.Find the K-th Character in String Game I/README_EN.md b/solution/3300-3399/3304.Find the K-th Character in String Game I/README_EN.md index 939cfd227d1d8..7798df88f7a86 100644 --- a/solution/3300-3399/3304.Find the K-th Character in String Game I/README_EN.md +++ b/solution/3300-3399/3304.Find the K-th Character in String Game I/README_EN.md @@ -161,6 +161,23 @@ function kthCharacter(k: number): string { } ``` +#### Rust + +```rust +impl Solution { + pub fn kth_character(k: i32) -> char { + let mut word = vec![0]; + while word.len() < k as usize { + let m = word.len(); + for i in 0..m { + word.push((word[i] + 1) % 26); + } + } + (b'a' + word[(k - 1) as usize] as u8) as char + } +} +``` + diff --git a/solution/3300-3399/3304.Find the K-th Character in String Game I/Solution.rs b/solution/3300-3399/3304.Find the K-th Character in String Game I/Solution.rs new file mode 100644 index 0000000000000..eb53821428ee0 --- /dev/null +++ b/solution/3300-3399/3304.Find the K-th Character in String Game I/Solution.rs @@ -0,0 +1,12 @@ +impl Solution { + pub fn kth_character(k: i32) -> char { + let mut word = vec![0]; + while word.len() < k as usize { + let m = word.len(); + for i in 0..m { + word.push((word[i] + 1) % 26); + } + } + (b'a' + word[(k - 1) as usize] as u8) as char + } +}