You are given a string s of even length. Split this string into two halves of equal lengths, and let a be the first half and b be the second half.

Two strings are alike if they have the same number of vowels ('a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U'). Notice that s contains uppercase and lowercase letters.

Return true if a and b are alike. Otherwise, return false.

&nbsp;
Example 1:

Input: s = "book"
Output: true
Explanation: a = "bo" and b = "ok". a has 1 vowel and b has 1 vowel. Therefore, they are alike.


Example 2:

Input: s = "textbook"
Output: false
Explanation: a = "text" and b = "book". a has 1 vowel whereas b has 2. Therefore, they are not alike.
Notice that the vowel o is counted twice.


&nbsp;
Constraints:


	2 &lt;= s.length &lt;= 1000
	s.length is even.
	s consists of uppercase and lowercase letters.


vowels = "aeiouAEIOU"

class Solution:
    def halvesAreAlike(self, S: str) -> bool:
        mid, ans = len(S) // 2, 0
        for i in range(mid):
            if S[i] in vowels: ans += 1
            if S[mid+i] in vowels: ans -=1
        return ans == 0
class Solution {
    public boolean halvesAreAlike(String s) {
        //add vowels to the set
        Set<Character> set = new HashSet<>();
        set.add('a');
        set.add('e');
        set.add('i');
        set.add('o');
        set.add('u');
        set.add('A');
        set.add('E');
        set.add('I');
        set.add('O');
        set.add('U');

        //find the mid
        int mid = s.length() / 2;
        int count = 0;
        //increment the count for left half, decrement count for the second half if its a vowel
        for (int i = 0; i < s.length(); i++)
            count += (set.contains(s.charAt(i))) ? ((i < mid) ? 1 : -1) : 0;
        //finally count should be 0 to match left and right half
        return count == 0;
    }
}
class Solution {
public:
    bool halvesAreAlike(string s) {
        unordered_set<char> set = {'a', 'e', 'i', 'o', 'u','A','I','E','O','U'};
        int i=0,j=s.size()/2,cnt=0;
        while(j<s.size()){
            if(set.find(s[i])!=set.end()) cnt++;
            if(set.find(s[j])!=set.end()) cnt--;
            i++;
            j++;
        }
        return cnt==0;
    }
};
var halvesAreAlike = function(s) {
    let isVowel = ["a","e","i","o","u","A","E","I","O","U"];
    let count = 0;
    for (let i = 0; i < s.length / 2; i++) {
        if (isVowel.indexOf(s[i]) !== -1) {
            count++;
        }
    }
    for (let i = s.length / 2; i < s.length; i++) {
        if (isVowel.indexOf(s[i]) !== -1) {
            count--;
        }
    }
    return count === 0;
};
Determine if String Halves Are Alike