题目描述:
1704. 判断字符串的两半是否相似 - 力扣(LeetCode) (leetcode-cn.com)
Java代码:
class Solution {
int[] m=new int['z'+1];
public int count(String s,int bg,int ed){
int cnt=0;
for(int i=bg;i<ed;i++)cnt+=m[s.charAt(i)];
return cnt;
}
public boolean halvesAreAlike(String s) {
for(int e:new int[]{'a','e','i','o','u'})m[e]=m[e-32]=1;
return count(s,0,s.length()/2)==count(s,s.length()/2,s.length());
}
}