2586. Count the Number of Vowel Strings in Range

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
class Solution {
private static final Set<Character> VOWEL_CHAR_SETS = new HashSet<>(Arrays.asList('a', 'e', 'i', 'o', 'u'));

public int vowelStrings(String[] words, int left, int right) {
int count = 0;
for (int i = left; i <= right; i++) {
if (ifVowelString(words[i])) {
count++;
}
}
return count;
}

private boolean ifVowelString(String word) {
return VOWEL_CHAR_SETS.contains(word.charAt(0)) && VOWEL_CHAR_SETS.contains(word.charAt(word.length() - 1));
}
}

References

2586. Count the Number of Vowel Strings in Range