class Solution {
public boolean halvesAreAlike(String s) {
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');
int n = s.length();
int cnt = 0;
for(int i = 0; i < n; i++) {
if(i < n /2) {
if (set.contains(s.charAt(i))) cnt++;
} else {
if (set.contains(s.charAt(i))) cnt--;
}
}
return cnt == 0;
}
}
标签:cnt,set,两半,int,add,字符串,1704
From: https://www.cnblogs.com/eiffelzero/p/16879916.html