Count Vowel Substrings of a String

找出所有包含五个元音字符的substring.

这题就是滑窗.

class Solution {
    public int countVowelSubstrings(String word) {
        int res = 0;
        for(int i = 0; i < word.length(); i++) {
            if(!check(word.charAt(i)))
                continue;
            else
            {
                Set<Character> set = new HashSet<>();
                for(int j = i; j < word.length(); j++) {
                    if(!check(word.charAt(j)))
                        break;
                    set.add(word.charAt(j));
                    if(set.size() == 5) // contain all fvie vowels
                        res++;
                }
            }
        }
        return res;
    }
    
    public boolean check(char c) {
        return c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u';
    }
}