LeetCode solutions

2186. Count Vowel Substrings of a String

My accepted Python solution to LeetCode problem 2186, Count Vowel Substrings of a String, running in 25ms.

  • Difficulty: Easy
  • Python
  • Runtime 25ms
  • Memory 17.3MB

Read the problem on LeetCode View on GitHub

Python

Accepted on LeetCode — runtime 25ms, memory 17.3MB, accepted 2025-12-31.

python
class Solution:
    def countVowelSubstrings(self, word: str) -> int:
        vowels = set('aeiou')
        count = 0
        n = len(word)
        for i in range(n):
            seen = set()
            for j in range(i, n):
                if word[j] not in vowels:
                    break
                seen.add(word[j])
                if len(seen) == 5:
                    count += 1
        return count

Source