没啥好方法,直接暴力求解了
class Solution {
public:
bool isvalid(string s1){
if (s1.find('a') != -1 && s1.find('e') != -1 && s1.find('i') != -1 && s1.find('o') != -1 && s1.find('u') != -1 )
return true;
else return false;
}
int countVowelSubstrings(string word) {
int res = 0,j;
string s = "aeiou";
int len = word.length();
for (int i = 0; i < len; i ++){
for (j = i ;j < i + 5 && j < len; j ++){
if (s.find(word[j]) == -1)
break;
}
if (j == i + 5){
string s2 = word.substr(i,j - i);
if (isvalid(s2)) res ++;
for (;j < len; j ++){
if (s.find(word[j]) != -1 && isvalid(word.substr(i,j - i + 1)))
res ++;
else if (s.find(word[j]) == -1)
break;
}
}
}
return res;
}
};