blob: 8d6b9191bf4e49a368887932bdfebf729f3cd6e3 (
plain) (
blame)
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
|
#!/usr/bin/env python3
# not my solution
class Solution:
def countVowelPermutation(self, n: int) -> int:
kMod = int(1e9) + 7
dp = {"a": 1, "e": 1, "i": 1, "o": 1, "u": 1}
for _ in range(n - 1):
newDp = {
"a": dp["e"] + dp["i"] + dp["u"],
"e": dp["a"] + dp["i"],
"i": dp["e"] + dp["o"],
"o": dp["i"],
"u": dp["i"] + dp["o"],
}
dp = newDp
return sum(dp.values()) % kMod
def main():
solution = Solution()
print(solution.countVowelPermutation(1))
print(solution.countVowelPermutation(2))
print(solution.countVowelPermutation(5))
if __name__ == "__main__":
main()
|