Problem Solving/LeetCode
Today's Challenge
fabichoi
2022. 12. 1. 23:45
https://leetcode.com/problems/determine-if-string-halves-are-alike/
Determine if String Halves Are Alike - LeetCode
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
더하고 빼기만 잘하면 되는 문제. lowercase로 바꿔도 상관 없어서 걍 바꿔서 처리함
class Solution:
def halvesAreAlike(self, s: str) -> bool:
s = s.lower()
vowels = ['a', 'e', 'i', 'o', 'u']
l, h, cnt = len(s), len(s) // 2, 0
for i in range(l):
if s[i] in vowels:
if i < h:
cnt += 1
else:
cnt -=1
return cnt == 0
반응형