From 68421f83023af723fd7b55c7b1e82dc9e0905320 Mon Sep 17 00:00:00 2001 From: yanglbme Date: Thu, 3 Jul 2025 06:41:45 +0800 Subject: [PATCH] feat: add rust solution to lc problem: No.3304 No.3304.Find the K-th Character in String Game I --- .../README.md | 17 +++++++++++++++++ .../README_EN.md | 17 +++++++++++++++++ .../Solution.rs | 12 ++++++++++++ 3 files changed, 46 insertions(+) create mode 100644 solution/3300-3399/3304.Find the K-th Character in String Game I/Solution.rs 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 + } +}