-
Notifications
You must be signed in to change notification settings - Fork 0
/
No_1456.cs
56 lines (46 loc) · 1.24 KB
/
No_1456.cs
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
namespace LeetCode
{
public class No_1456
{
public int MaxVowels(string s, int k)
{
int max = 0;
var vowels = "aeiou";
for (int i = 0; i < k; i++)
if (vowels.Contains(s[i]))
max++;
int e = k - 1, m = max;
while (e < s.Length - 1)
{
e++;
if (vowels.Contains(s[e - k]))
m--;
if (vowels.Contains(s[e]))
m++;
if (m > max)
max = m;
}
return max;
}
/// <summary>
/// Time Limit Exceded
/// </summary>
public int MaxVowels1(string s, int k)
{
int max = 0;
var cad = s.ToCharArray();
for (int i = 0; i <= cad.Length - k; i++)
{
var c = 0;
for (int j = i; j < i + k; j++)
{
if (cad[j] == 'a' || cad[j] == 'e' || cad[j] == 'i' || cad[j] == 'o' || cad[j] == 'u')
c++;
}
if (c > max)
max = c;
}
return max;
}
}
}