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
else: return False
|
cs |
반응형
'python-algorithm' 카테고리의 다른 글
leetcode 557. Reverse Words in a String III (0) | 2022.03.17 |
---|---|
leetcode 2000. Reverse Prefix of Word (0) | 2022.03.16 |
leetcode 1464. Maximum Product of Two Elements in an Array (0) | 2022.03.16 |
leetcode 125. Valid Palindrome (0) | 2022.03.15 |
leetcode 2108. Find First Palindromic String in the Array (0) | 2022.03.15 |
댓글