bumpsoo 2025-01-02 22:21:05 +09:00
parent f5391da3ab
commit 6cda4101f9

View file

@ -0,0 +1,24 @@
# https://leetcode.com/problems/count-vowel-strings-in-ranges
from typing import List
VOWEL = {
'a': True,
'e': True,
'i': True,
'o': True,
'u': True,
}
class Solution:
def vowelStrings(self, words: List[str], queries: List[List[int]]) -> List[int]:
sums = [0]
for word in words:
if word[0] in VOWEL and word[-1] in VOWEL:
sums.append(sums[-1] + 1)
else:
sums.append(sums[-1])
result = []
for [start, end] in queries:
result.append(sums[end + 1] - sums[start])
return result