leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE |
2947.cpp (638B)
0 class Solution {
1 static inline bool isVowel(const char c) {
2 return c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u';
3 }
5 public:
6 int beautifulSubstrings(const string &s, int k) const {
7 const int n = s.size();
8 int res = 0;
9 for (int i = 0; i < n; i++) {
10 int vowels = 0, consonants = 0;
11 for (int j = i; j < n; j++) {
12 isVowel(s[j]) ? vowels++ : consonants++;
13 if (vowels != consonants) continue;
14 if ((vowels * consonants) % k != 0) continue;
15 res++;
16 }
17 }
18 return res;
19 }
20 };