leetcode

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

commitf99ee8906d052737b2dfcc137549cbf1c4a1358d
parent186191481d9af994dacc615ac52a534f33d8365c
authorDimitrije Dobrota <mail@dimitrijedobrota.com>
dateSun, 26 Nov 2023 22:00:45 +0000

1 Random Problem

Diffstat:
AProblems/2947.cpp|+++++++++++++++++++++
MREADME.md|+

2 files changed, 22 insertions(+), 0 deletions(-)


diff --git a/Problems/2947.cpp b/Problems/2947.cpp

@@ -0,0 +1,21 @@

class Solution {
static inline bool isVowel(const char c) {
return c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u';
}
public:
int beautifulSubstrings(const string &s, int k) const {
const int n = s.size();
int res = 0;
for (int i = 0; i < n; i++) {
int vowels = 0, consonants = 0;
for (int j = i; j < n; j++) {
isVowel(s[j]) ? vowels++ : consonants++;
if (vowels != consonants) continue;
if ((vowels * consonants) % k != 0) continue;
res++;
}
}
return res;
}
};

diff --git a/README.md b/README.md

@@ -923,3 +923,4 @@ for solving problems.

| 2856 | Medium | [Minimum Array Length After Pair Removals](Problems/2856.cpp) |
| 2895 | Medium | [Minimum Processing Time](Problems/2895.cpp) |
| 2900 | Medium | [Longest Unequal Adjacent Groups Subsequence I](Problems/2900.cpp) |
| 2947 | Medium | [Count Beautiful Substrings I](Problems/2947.cpp) |