본문 바로가기
python-algorithm

leetcode 1704. Determine if String Halves Are Alike

by 무적김두칠 2022. 3. 16.

1
2
3
4
5
6
7
8
9
10
11
12
13
class Solution:
    def halvesAreAlike(self, s: str-> bool:
        vowel=['a''e''i''o''u''A''E''I''O''U']
        half1=s[:len(s)//2]
        half2=s[len(s)//2:]
        half1Cnt=0
        for i in half1:
            if i in vowel: half1Cnt+=1
        half2Cnt=0
        for i in half2:
            if i in vowel: half2Cnt+=1
        if half1Cnt==half2Cnt : return True
        elsereturn False
cs
반응형

댓글