Skip to content

Commit b14a6a1

Browse files
committed
Add solution #1220
1 parent 7fa4af7 commit b14a6a1

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 1,183 LeetCode solutions in JavaScript
1+
# 1,184 LeetCode solutions in JavaScript
22

33
[https://leetcodejavascript.com](https://leetcodejavascript.com)
44

@@ -937,6 +937,7 @@
937937
1217|[Minimum Cost to Move Chips to The Same Position](./solutions/1217-minimum-cost-to-move-chips-to-the-same-position.js)|Easy|
938938
1218|[Longest Arithmetic Subsequence of Given Difference](./solutions/1218-longest-arithmetic-subsequence-of-given-difference.js)|Medium|
939939
1219|[Path with Maximum Gold](./solutions/1219-path-with-maximum-gold.js)|Medium|
940+
1220|[Count Vowels Permutation](./solutions/1220-count-vowels-permutation.js)|Hard|
940941
1232|[Check If It Is a Straight Line](./solutions/1232-check-if-it-is-a-straight-line.js)|Easy|
941942
1233|[Remove Sub-Folders from the Filesystem](./solutions/1233-remove-sub-folders-from-the-filesystem.js)|Medium|
942943
1249|[Minimum Remove to Make Valid Parentheses](./solutions/1249-minimum-remove-to-make-valid-parentheses.js)|Medium|
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/**
2+
* 1220. Count Vowels Permutation
3+
* https://leetcode.com/problems/count-vowels-permutation/
4+
* Difficulty: Hard
5+
*
6+
* Given an integer n, your task is to count how many strings of length n can be formed under
7+
* the following rules:
8+
* - Each character is a lower case vowel ('a', 'e', 'i', 'o', 'u')
9+
* - Each vowel 'a' may only be followed by an 'e'.
10+
* - Each vowel 'e' may only be followed by an 'a' or an 'i'.
11+
* - Each vowel 'i' may not be followed by another 'i'.
12+
* - Each vowel 'o' may only be followed by an 'i' or a 'u'.
13+
* - Each vowel 'u' may only be followed by an 'a'.
14+
*
15+
* Since the answer may be too large, return it modulo 10^9 + 7.
16+
*/
17+
18+
/**
19+
* @param {number} n
20+
* @return {number}
21+
*/
22+
var countVowelPermutation = function(n) {
23+
const MOD = 1000000007n;
24+
let aCount = 1n;
25+
let eCount = 1n;
26+
let iCount = 1n;
27+
let oCount = 1n;
28+
let uCount = 1n;
29+
30+
for (let length = 2; length <= n; length++) {
31+
const prevACount = aCount;
32+
const prevECount = eCount;
33+
const prevICount = iCount;
34+
const prevOCount = oCount;
35+
const prevUCount = uCount;
36+
37+
aCount = (prevECount + prevICount + prevUCount) % MOD;
38+
eCount = (prevACount + prevICount) % MOD;
39+
iCount = (prevECount + prevOCount) % MOD;
40+
oCount = (prevICount) % MOD;
41+
uCount = (prevICount + prevOCount) % MOD;
42+
}
43+
44+
const total = aCount + eCount + iCount + oCount + uCount;
45+
46+
return Number(total % MOD);
47+
};

0 commit comments

Comments
 (0)