int maxVowels(string s, int k) {
unordered_map<char, int> window;
int l = 0, r = 0;
bool flag1 = false;
int count = 0;
int res = 0;
while (r < s.size()) {
if (!flag1) count++, window[s[r++]]++;
bool flag2 = false;
if (count == k)
//窗口内包含了k个字符
flag2 = true;
if (flag2) {
res = max(res, window['e'] + window['a'] + window['i'] + window['o'] + window['u']);
window[s[l++]]--;
count--;
flag1 = true;
} else
flag1 = false;
}
return res;
}
1456. 定长子串中元音的最大数目
最新推荐文章于 2022-12-30 16:25:21 发布