알고리즘
[알고리즘] Determine if String Halves Are Alike
keel_im
2021. 4. 7. 16:35
반응형
포인트
- 단어를 반으로 나누고 모음(vowels) 개수를 카운팅 하는 문제입니다.
🧶문서는 항상 수정될 수 있습니다. 비판은 환영합니다.
python
class Solution:
def halvesAreAlike(self, s: str) -> bool:
temp = len(s) // 2
a = s[:temp]
b = s[temp:]
vowels = 'aeiouAEIOU'
acount, bcount = 0, 0
for char in vowels:
acount += a.count(char)
bcount += b.count(char)
return acount == bcount
반응형