-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution.cs
More file actions
28 lines (27 loc) · 714 Bytes
/
Solution.cs
File metadata and controls
28 lines (27 loc) · 714 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
public class Solution
{
public int BeautifulSubstrings(string s, int k)
{
int n = s.Length;
int[] count = new int[n + 1];
for (int i = 0; i < n; ++i)
{
count[i + 1] = count[i] + (IsVowel(s[i]) ? 1 : 0);
}
int ret = 0;
for (int i = 0; i < n; ++i)
{
for (int j = 0; j <= i; ++j)
{
int len = i - j + 1;
int vowels = count[i + 1] - count[j];
if (vowels * 2 == len && vowels * vowels % k == 0) ret++;
}
}
return ret;
}
bool IsVowel(char a)
{
return a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u';
}
}