[LeetCode] Count the Number of Vowel Strings in Range

2586. Count the Number of Vowel Strings in Range

You are given a 0-indexed array of string words and two integers left and right.

A string is called a vowel string if it starts with a vowel character and ends with a vowel character where vowel characters are ‘a’, ‘e’, ‘i’, ‘o’, and ‘u’.

Return the number of vowel strings words[i] where i belongs to the inclusive range [left, right].

1
2
3
4
5
6
7
8
9
10
11
12
class Solution {
public:
int vowelStrings(vector<string>& words, int left, int right) {
unordered_set<char> us{'a','e','i','o','u'};
int res = 0;
for(int i = left; i <= right; i++) {
if(us.count(words[i].front()) and us.count(words[i].back())) res += 1;
}
return res;
}
};

Author: Song Hayoung
Link: https://songhayoung.github.io/2023/03/12/PS/LeetCode/count-the-number-of-vowel-strings-in-range/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.