python-algorithm
leetcode 2586. Count the Number of Vowel Strings in Range
무적김두칠
2024. 2. 9. 22:28
https://leetcode.com/problems/count-the-number-of-vowel-strings-in-range/description/
LeetCode - The World's Leading Online Programming Learning Platform
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
class Solution:
def vowelStrings(self, words: List[str], left: int, right: int) -> int:
def is_vowel(s):
vowels = 'aeiou'
chk1 = chk2 =0
for vowel in vowels:
if s.startswith(vowel):
chk1 = 1
if s.endswith(vowel):
chk2 = 1
return chk1 * chk2
answer = 0
for i in range(left, right + 1):
answer += is_vowel(words[i])
return answer
|
cs |
left 부터 right 범위 사이에 있는 word 들이 모음으로 시작해서 모음으로 끝나는지 체크하면됨
반응형