Leetcode 1823 Solution

This article provides solution to leetcode question 1823 (determine-if-string-halves-are-alike)

https://leetcode.com/problems/determine-if-string-halves-are-alike

Solution

class Solution:
    def halvesAreAlike(self, s: str) -> bool:
        n = len(s)

        s1 = s[:n // 2]
        s2 = s[n // 2:]

        def get_vowels(s):
            cnt = 0
            for ch in s:
                if ch in ['a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U']:
                    cnt += 1
            return cnt

        return get_vowels(s1) == get_vowels(s2)