From 6cda4101f904e7e6828eef56b95f655336d037bd Mon Sep 17 00:00:00 2001 From: bumpsoo Date: Thu, 2 Jan 2025 22:21:05 +0900 Subject: [PATCH] https://leetcode.com/problems/count-vowel-strings-in-ranges --- medium/count_vowel_strings_in_ranges.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 medium/count_vowel_strings_in_ranges.py diff --git a/medium/count_vowel_strings_in_ranges.py b/medium/count_vowel_strings_in_ranges.py new file mode 100644 index 0000000..5ae07f9 --- /dev/null +++ b/medium/count_vowel_strings_in_ranges.py @@ -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 +