diff --git a/solution/1200-1299/1220.Count Vowels Permutation/README.md b/solution/1200-1299/1220.Count Vowels Permutation/README.md index 0180a1370eb7d..d088f05ecb2c1 100644 --- a/solution/1200-1299/1220.Count Vowels Permutation/README.md +++ b/solution/1200-1299/1220.Count Vowels Permutation/README.md @@ -249,6 +249,32 @@ class Solution { } ``` +```java +class Solution { + public int countVowelPermutation(int n) { + final int mod = 1000000007; + long countA = 1, countE = 1, countI = 1, countO = 1, countU = 1; + for (int length = 1; length < n; length++) { + // Calculate the next counts for each vowel based on the previous counts + long nextCountA = countE; + long nextCountE = (countA + countI) % mod; + long nextCountI = (countA + countE + countO + countU) % mod; + long nextCountO = (countI + countU) % mod; + long nextCountU = countA; + // Update the counts with the newly calculated values for the next length + countA = nextCountA; + countE = nextCountE; + countI = nextCountI; + countO = nextCountO; + countU = nextCountU; + } + // Calculate the total count of valid strings for length n + long totalCount = (countA + countE + countI + countO + countU) % mod; + return (int) totalCount; + } +} +``` + ### **C++** ```cpp diff --git a/solution/1200-1299/1220.Count Vowels Permutation/README_EN.md b/solution/1200-1299/1220.Count Vowels Permutation/README_EN.md index 6e25c190a80b7..16c94e76c10a6 100644 --- a/solution/1200-1299/1220.Count Vowels Permutation/README_EN.md +++ b/solution/1200-1299/1220.Count Vowels Permutation/README_EN.md @@ -215,6 +215,32 @@ class Solution { } ``` +```java +class Solution { + public int countVowelPermutation(int n) { + final int mod = 1000000007; + long countA = 1, countE = 1, countI = 1, countO = 1, countU = 1; + for (int length = 1; length < n; length++) { + // Calculate the next counts for each vowel based on the previous counts + long nextCountA = countE; + long nextCountE = (countA + countI) % mod; + long nextCountI = (countA + countE + countO + countU) % mod; + long nextCountO = (countI + countU) % mod; + long nextCountU = countA; + // Update the counts with the newly calculated values for the next length + countA = nextCountA; + countE = nextCountE; + countI = nextCountI; + countO = nextCountO; + countU = nextCountU; + } + // Calculate the total count of valid strings for length n + long totalCount = (countA + countE + countI + countO + countU) % mod; + return (int) totalCount; + } +} +``` + ### **C++** ```cpp