[LeetCode] Trim Trailing Vowels

3856. Trim Trailing Vowels

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'.

1
2
3
4
5
6
7
8
class Solution {
public:
string trimTrailingVowels(string s) {
unordered_set<char> us{'a','e','i','o','u'};
while(s.size() and us.count(s.back())) s.pop_back();
return s;
}
};
Author: Song Hayoung
Link: https://songhayoung.github.io/2026/09/04/PS/LeetCode/trim-trailing-vowels/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.