题目:
代码(首刷自解 day10):
class Solution {
public:
bool isVowel(char ch){
return ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u';
}
int maxVowels(string s, int k) {
int n=s.size();
int countOfVowel=0;
for(int i=0;i<k;++i){
if(isVowel(s[i])){
countOfVowel++;
}
}
int maxCount=countOfVowel;
for(int i=k;i<n;++i){
if(isVowel(s[i])) countOfVowel++;
if(isVowel(s[i-k])) countOfVowel--;
maxCount=max(maxCount,countOfVowel);
}
return maxCount;
}
};