题目分析:
暴力法
代码如下:
class Solution {
public int findTheLongestSubstring(String s) {
int []a = new int [s.length()+1];
int []e = new int [s.length()+1];
int []i = new int [s.length()+1];
int []o = new int [s.length()+1];
int []u = new int [s.length()+1];
a[0] = 0;
e[0] = 0;
i[0] = 0;
o[0] = 0;
u[0] = 0;
for(int index = 1; index<=s.length();index++){
a[index] = a[index-1];
e[index] = e[index-1];
i[index] = i[index-1];
o[index] = o[index-1];
u[index] = u[index-1];
switch(s.charAt(index-1)){
case'a':a[index] += 1;break;
case'e':e[index] += 1;break;
case'i':i[index] += 1;break;
case'o':o[index] += 1;break;
case'u':u[index] += 1;break;
default:break;
}
}
int index1 = s.length();
int index2 = 0;
for(int index = s.length();index > 0; index--){
index1 = index;
index2 = 0;
while(index1 <= s.length()){
int a12 = a[index1]-a[index2];
int e12 = e[index1]-e[index2];
int i12 = i[index1]-i[index2];
int o12 = o[index1]-o[index2];
int u12 = u[index1]-u[index2];
if(a12%2 == 0 && e12 % 2 == 0 && i12 % 2 == 0 && i12 % 2 == 0
&& o12 % 2 == 0 && u12 % 2 ==0){
return index1-index2;
}
index1++;
index2++;
}
}
return 0;
}
}