This commit is contained in:
parent
f5391da3ab
commit
6cda4101f9
1 changed files with 24 additions and 0 deletions
24
medium/count_vowel_strings_in_ranges.py
Normal file
24
medium/count_vowel_strings_in_ranges.py
Normal 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
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue