#3856
Easy Algorithms Trim trailing vowels
String
77.1% acceptance
Mar 15, 2026
28
0
You are given a string s that consists of lowercase English letters.
Return the string obtained by removing all trailing vowels from s.
The vowels consist of the characters 'a', 'e', 'i', 'o', and 'u'.
Solution
Rust
Time O(n)
Space O(1)
impl Solution {
pub fn trim_trailing_vowels(s: String) -> String {
let vowels = b"aeiou";
let bytes = s.as_bytes();
let mut end = bytes.len();
while end > 0 && vowels.contains(&bytes[end - 1]) {
end -= 1;
}
s[..end].to_string()
}
}