diff --git a/solution/2500-2599/2586.Count the Number of Vowel Strings in Range/README.md b/solution/2500-2599/2586.Count the Number of Vowel Strings in Range/README.md index 4a33c3c276214..83586a9bc9400 100644 --- a/solution/2500-2599/2586.Count the Number of Vowel Strings in Range/README.md +++ b/solution/2500-2599/2586.Count the Number of Vowel Strings in Range/README.md @@ -150,6 +150,30 @@ function vowelStrings(words: string[], left: number, right: number): number { } ``` +### **Rust** + +```rust +impl Solution { + pub fn vowel_strings(words: Vec, left: i32, right: i32) -> i32 { + let check = |c: u8| -> bool { + c == b'a' || c == b'e' || c == b'i' || c == b'o' || c == b'u' + }; + + let mut ans = 0; + for i in left..=right { + let words_bytes = words[i as usize].as_bytes(); + let first_char = words_bytes[0]; + let last_char = words_bytes[words_bytes.len() - 1]; + if check(first_char) && check(last_char) { + ans += 1; + } + } + + ans + } +} +``` + ### **...** ``` diff --git a/solution/2500-2599/2586.Count the Number of Vowel Strings in Range/README_EN.md b/solution/2500-2599/2586.Count the Number of Vowel Strings in Range/README_EN.md index 46dff73a4c86a..9f9b671658f33 100644 --- a/solution/2500-2599/2586.Count the Number of Vowel Strings in Range/README_EN.md +++ b/solution/2500-2599/2586.Count the Number of Vowel Strings in Range/README_EN.md @@ -140,6 +140,30 @@ function vowelStrings(words: string[], left: number, right: number): number { } ``` +### **Rust** + +```rust +impl Solution { + pub fn vowel_strings(words: Vec, left: i32, right: i32) -> i32 { + let check = |c: u8| -> bool { + c == b'a' || c == b'e' || c == b'i' || c == b'o' || c == b'u' + }; + + let mut ans = 0; + for i in left..=right { + let words_bytes = words[i as usize].as_bytes(); + let first_char = words_bytes[0]; + let last_char = words_bytes[words_bytes.len() - 1]; + if check(first_char) && check(last_char) { + ans += 1; + } + } + + ans + } +} +``` + ### **...** ``` diff --git a/solution/2500-2599/2586.Count the Number of Vowel Strings in Range/Solution.rs b/solution/2500-2599/2586.Count the Number of Vowel Strings in Range/Solution.rs new file mode 100644 index 0000000000000..f8d6735e9b4ef --- /dev/null +++ b/solution/2500-2599/2586.Count the Number of Vowel Strings in Range/Solution.rs @@ -0,0 +1,19 @@ +impl Solution { + pub fn vowel_strings(words: Vec, left: i32, right: i32) -> i32 { + let check = |c: u8| -> bool { + c == b'a' || c == b'e' || c == b'i' || c == b'o' || c == b'u' + }; + + let mut ans = 0; + for i in left..=right { + let words_bytes = words[i as usize].as_bytes(); + let first_char = words_bytes[0]; + let last_char = words_bytes[words_bytes.len() - 1]; + if check(first_char) && check(last_char) { + ans += 1; + } + } + + ans + } +} \ No newline at end of file