-
Notifications
You must be signed in to change notification settings - Fork 122
/
Copy path1641. Count Sorted Vowel Strings.cpp
70 lines (59 loc) · 1.1 KB
/
1641. Count Sorted Vowel Strings.cpp
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// 1641.✅ Count Sorted Vowel Strings
class Solution
{
public:
int countVowelStrings(int n)
{
vector<int> v(5, 1);
for (int i = 2; i <= n; ++i)
{
for (int i = 3; i >= 0; --i)
{
v[i] += v[i + 1];
}
}
return accumulate(v.begin(), v.end(), 0);
}
};
class Solution
{
public:
int countVowelStrings(int n)
{
int a = 1, e = 1, i = 1, o = 1, u = 1;
while (--n)
{
o += u;
i += o;
e += i;
a += e;
}
return a + e + i + o + u;
}
};
class Solution
{
public:
vector<char> v = {'a', 'e', 'i', 'o', 'u'};
int cnt(int len, char last_char)
{
if (len == 0)
return 1;
int temp = 0;
for (char i : v)
{
if (last_char >= i)
temp += cnt(len - 1, i);
}
return temp;
}
int countVowelStrings(int n)
{
int ans = 0;
for (char i : v)
{
ans += cnt(n - 1, i);
}
return ans;
}
};