leetcode

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

1839.cpp (594B)


      1 class Solution {
      2   public:
      3     int longestBeautifulSubstring(const string &word) const {
      4         static const char *order = "aeiou";
      5         int i = 0, j = 0, cnt = 0;
      6         int res = 0;
      7 
      8         while (i < size(word)) {
      9             if (word[i] == order[j]) {
     10                 while (word[i] == order[j])
     11                     i++, cnt++;
     12                 if (++j == 5) res = max(res, cnt);
     13             } else {
     14                 while (i < size(word) && word[i] != 'a')
     15                     i++;
     16                 cnt = 0;
     17                 j = 0;
     18             }
     19         }
     20 
     21         return res;
     22     }
     23 };