滑动窗口
定长窗口:
class Solution {
public:
int maxVowels(string s, int k) {
int cnt = 0, res = -1;
int i = 0, j = -1;
while(j < (int)s.size() - 1) {
j ++;
if(s[j] == 'a' || s[j] == 'e' || s[j] == 'i' || s[j] == 'o' || s[j] == 'u') {
cnt ++;
}
if(j - i + 1 == k) {
res = max(res, cnt);
if(s[i] == 'a' || s[i] == 'e' || s[i] == 'i' || s[i] == 'o' || s[i] == 'u') {
cnt --;
}
i ++;
}
}
return res;
}
};