leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE |
1456.cpp (470B)
0 class Solution {
1 bool isVowel(char c) { return c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u'; }
3 public:
4 int maxVowels(string s, int k) {
5 int i, cnt = 0;
6 for (i = 0; i < k; i++)
7 if (isVowel(s[i])) cnt++;
9 int maxi = cnt;
10 for (; i < s.size(); i++) {
11 if (isVowel(s[i - k])) cnt--;
12 if (isVowel(s[i])) cnt++;
13 maxi = max(maxi, cnt);
14 }
16 return maxi;
17 }
18 };