Skip to content

Commit fb77045

Browse files
authored
Update README.md
1 parent 570cedc commit fb77045

File tree

1 file changed

+26
-0
lines changed
  • solution/1200-1299/1220.Count Vowels Permutation

1 file changed

+26
-0
lines changed

solution/1200-1299/1220.Count Vowels Permutation/README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,32 @@ class Solution {
249249
}
250250
```
251251

252+
```java
253+
class Solution {
254+
public int countVowelPermutation(int n) {
255+
final int mod = 1000000007;
256+
long countA = 1, countE = 1, countI = 1, countO = 1, countU = 1;
257+
for (int length = 1; length < n; length++) {
258+
// Calculate the next counts for each vowel based on the previous counts
259+
long nextCountA = countE;
260+
long nextCountE = (countA + countI) % mod;
261+
long nextCountI = (countA + countE + countO + countU) % mod;
262+
long nextCountO = (countI + countU) % mod;
263+
long nextCountU = countA;
264+
// Update the counts with the newly calculated values for the next length
265+
countA = nextCountA;
266+
countE = nextCountE;
267+
countI = nextCountI;
268+
countO = nextCountO;
269+
countU = nextCountU;
270+
}
271+
// Calculate the total count of valid strings for length n
272+
long totalCount = (countA + countE + countI + countO + countU) % mod;
273+
return (int) totalCount;
274+
}
275+
}
276+
```
277+
252278
### **C++**
253279

254280
```cpp

0 commit comments

Comments
 (0)