Problem Solving/LeetCode
2023.10.30 Today's Challenge
fabichoi
2023. 10. 30. 23:45
https://leetcode.com/problems/count-vowels-permutation/?envType=daily-question&envId=2023-10-28
Count Vowels Permutation - LeetCode
Can you solve this real interview question? Count Vowels Permutation - Given an integer n, your task is to count how many strings of length n can be formed under the following rules: * Each character is a lower case vowel ('a', 'e', 'i', 'o', 'u') * Each
leetcode.com
이것도 왜 hard지..?
class Solution:
def countVowelPermutation(self, n: int) -> int:
MOD = 10**9 + 7
a, e, i, o, u = 1, 1, 1, 1, 1
for _ in range(1, n):
a_next = e
e_next = (a + i) % MOD
i_next = (a + e + o + u) % MOD
o_next = (i + u) % MOD
u_next = a
a, e, i, o, u = a_next, e_next, i_next, o_next, u_next
return (a + e + i + o + u) % MOD
반응형