Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- int beautifulSubstrings(string s, int k) {
- int n = s.length();
- std::unordered_set<char> vowels = {'a', 'e', 'i', 'o', 'u'};
- int count = 0;
- for (int i = 0; i < n; ++i) {
- int vowelCount = 0, consonantCount = 0;
- for (int j = i; j < n; ++j) {
- if (vowels.count(tolower(s[j])))
- vowelCount++;
- else
- consonantCount++;
- if (vowelCount == consonantCount && (vowelCount * consonantCount) % k == 0)
- count++;
- }
- }
- return count;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment