Determine if String Halves Are Alike

easy string counting

Problem

Given an even-length string s, decide if its first half and second half contain the same number of vowels (aeiouAEIOU).

Inputs = "book"
Outputtrue
"bo" has 1 vowel, "ok" has 1 vowel.

def halves_are_alike(s):
    vowels = set('aeiouAEIOU')
    half = len(s) // 2
    a = sum(1 for c in s[:half] if c in vowels)
    b = sum(1 for c in s[half:] if c in vowels)
    return a == b
function halvesAreAlike(s) {
  const v = new Set("aeiouAEIOU");
  const half = s.length / 2;
  let a = 0, b = 0;
  for (let i = 0; i < half; i++) if (v.has(s[i])) a++;
  for (let i = half; i < s.length; i++) if (v.has(s[i])) b++;
  return a === b;
}
class Solution {
    public boolean halvesAreAlike(String s) {
        String v = "aeiouAEIOU";
        int half = s.length() / 2, a = 0, b = 0;
        for (int i = 0; i < half; i++) if (v.indexOf(s.charAt(i)) >= 0) a++;
        for (int i = half; i < s.length(); i++) if (v.indexOf(s.charAt(i)) >= 0) b++;
        return a == b;
    }
}
bool halvesAreAlike(string s) {
    string v = "aeiouAEIOU";
    int half = s.size() / 2, a = 0, b = 0;
    for (int i = 0; i < half; i++) if (v.find(s[i]) != string::npos) a++;
    for (int i = half; i < (int)s.size(); i++) if (v.find(s[i]) != string::npos) b++;
    return a == b;
}
Time: O(n) Space: O(1)