Untitled

 avatar
unknown
plain_text
a year ago
539 B
6
Indexable
class Solution {
    private static final Set<Character> vowels = Set.of('a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U');

    public boolean halvesAreAlike(String s) {
        int balance = 0;

        for (int i = 0; i < s.length(); i++) {
            boolean isVowel = vowels.contains(s.charAt(i));
            if (isVowel) {
                if (i < s.length() / 2) {
                    balance++;
                } else {
                    balance--;
                }
            }
        }

        return balance == 0;
    }
}
Editor is loading...
Leave a Comment