Problem statement

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

Solution

Very easy problem, we just need to do what is asked. Let us first make all symbols lowercase, evaluate n: length of our string and define cand = set("aeiou") for quick check if letter is vowel.

Then we jut calculate number of vowels in each half and return result.

Complexity

It is just O(n), where n is the length of the string s.

Code

class Solution:
    def halvesAreAlike(self, s):
        s, n, cand = s.lower(), len(s), set("aeiou")
        return sum(i in cand for i in s[:n//2]) == sum(i in cand for i in s[n//2:])