2063. Vowels of All Substrings
Read the full problem statement on LeetCode.
Difficulty: medium Acceptance: 55% Topics: Math, String, Dynamic Programming, Combinatorics
View full problem on LeetCode Reading material
Reference solution (spoiler · python)
# Time: O(n)
# Space: O(1)
class Solution(object):
def countVowels(self, word):
"""
:type word: str
:rtype: int
"""
VOWELS = set("aeiou")
return sum((i-0+1) * ((len(word)-1)-i+1) for i, c in enumerate(word) if c in VOWELS)
Solution from kamyu104/LeetCode-Solutions · MIT