본문 바로가기
python-algorithm

leetcode 2586. Count the Number of Vowel Strings in Range

by 무적김두칠 2024. 2. 9.

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 들이 모음으로 시작해서 모음으로 끝나는지 체크하면됨

반응형

'python-algorithm' 카테고리의 다른 글

leetcode 3033. Modify the Matrix  (1) 2024.02.13
leetcode 2357. Make Array Zero by Subtracting Equal Amounts  (1) 2024.02.09
백준 Not A + B  (0) 2024.02.09
백준 27465 소수가 아닌 수  (0) 2024.02.09
백준 14215 세 막대  (0) 2024.02.08

댓글