Skip to content

Commit 16c3057

Browse files
authored
Merge pull request #941 from Vitali-Matteo/patch-17
Create 1220-Count-Vowels-Permutation.py
2 parents 26b1f5b + 35ff9a4 commit 16c3057

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

Diff for: python/1220-Count-Vowels-Permutation.py

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
class Solution:
2+
Memo = {}
3+
def countVowelPermutation(self, n, c = '') -> int:
4+
if (c, n) in self.Memo:
5+
return self.Memo[(c, n)]
6+
if n == 1:
7+
if c == 'a':
8+
return 1
9+
if c == 'e':
10+
return 2
11+
if c == 'i':
12+
return 4
13+
if c == 'o':
14+
return 2
15+
if c == 'u':
16+
return 1
17+
if c == '':
18+
return 5
19+
else:
20+
if c == 'a':
21+
self.Memo[('a', n)] = self.countVowelPermutation(n - 1, 'e')
22+
return self.Memo[('a', n)]
23+
if c == 'e':
24+
self.Memo[('e', n)] = self.countVowelPermutation(n - 1, 'a') + self.countVowelPermutation(n - 1, 'i')
25+
return self.Memo[('e', n)]
26+
if c == 'i':
27+
self.Memo[('i', n)] = self.countVowelPermutation(n - 1, 'a') + self.countVowelPermutation(n - 1, 'e') + self.countVowelPermutation(n - 1, 'o') + self.countVowelPermutation(n - 1, 'u')
28+
return self.Memo[('i', n)]
29+
if c == 'o':
30+
self.Memo[('o', n)] = self.countVowelPermutation(n - 1, 'i') + self.countVowelPermutation(n - 1, 'u')
31+
return self.Memo[('o', n)]
32+
if c == 'u':
33+
self.Memo[('u', n)] = self.countVowelPermutation(n - 1, 'a')
34+
return self.Memo[('u', n)]
35+
if c == '':
36+
Tot = 0
37+
for i in ['a', 'e', 'i', 'o', 'u']:
38+
Tot = Tot + self.countVowelPermutation(n - 1, i);
39+
return Tot % 1000000007

0 commit comments

Comments
 (0)