2062. Count Vowel Substrings of a String (Easy) - TengnanYao/daily_leetcode GitHub Wiki

class Solution:
    def countVowelSubstrings(self, word: str) -> int:
        h = {}
        start = -1
        result = 0
        i = 0
        while i < len(word):
            c = word[i]
            if c in "aeiou":
                if start == -1:
                    start = i
                h[c] = h.get(c, 0) + 1
                if len(h) == 5:
                    h2 = {k: v for k, v in h.items()}
                    for j in range(start, i):
                        result += 1
                        c2 = word[j]
                        h2[c2] -= 1
                        if h2[c2] == 0:
                            break
            else:
                start = -1
                h = {}
            i += 1
        return result