https://leetcode.com/problems/count-vowel-substrings/
- Sliding Window
For each position, expand window to include all vowels; count substrings ending at each vowel.
O(n)
O(1)
class Solution {
public int countVowelSubstrings(String word) {
int ans = 0, left = 0;
String vowels = "aeiou";
for (int right = 0; right < word.length(); right++) {
if (!vowels.contains(String.valueOf(word.charAt(right)))) left = right + 1;
else ans += right - left + 1;
}
return ans;
}
}