leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

1456.cpp (470B)


      1 class Solution {
      2     bool isVowel(char c) { return c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u'; }
      3 
      4   public:
      5     int maxVowels(string s, int k) {
      6         int i, cnt = 0;
      7         for (i = 0; i < k; i++)
      8             if (isVowel(s[i])) cnt++;
      9 
     10         int maxi = cnt;
     11         for (; i < s.size(); i++) {
     12             if (isVowel(s[i - k])) cnt--;
     13             if (isVowel(s[i])) cnt++;
     14             maxi = max(maxi, cnt);
     15         }
     16 
     17         return maxi;
     18     }
     19 };