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
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
Python
Accepted on LeetCode — runtime 25ms, memory 17.3MB, accepted 2025-12-31.
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