leetcode

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

2947.cpp (638B)


      1 class Solution {
      2     static inline bool isVowel(const char c) {
      3         return c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u';
      4     }
      5 
      6   public:
      7     int beautifulSubstrings(const string &s, int k) const {
      8         const int n = s.size();
      9         int res = 0;
     10         for (int i = 0; i < n; i++) {
     11             int vowels = 0, consonants = 0;
     12             for (int j = i; j < n; j++) {
     13                 isVowel(s[j]) ? vowels++ : consonants++;
     14                 if (vowels != consonants) continue;
     15                 if ((vowels * consonants) % k != 0) continue;
     16                 res++;
     17             }
     18         }
     19         return res;
     20     }
     21 };