1704. Determine if String Halves Are Alike

Updated: 2024-03-12
1 min read
[]

On This Page

LeetCode problem 1704

class Solution:
    def halvesAreAlike(self, s: str) -> bool:
        vowels = set('aeiouAEIOU')
        a, b = s[: len(s) >> 1], s[len(s) >> 1 :]
        return sum(c in vowels for c in a) == sum(c in vowels for c in b)