Skip to content

Commit de5b02c

Browse files
authored
Update 1641-count-sorted-vowel-strings.js
1 parent 9931eb0 commit de5b02c

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

1641-count-sorted-vowel-strings.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,23 @@ const countVowelStrings = function (n) {
1919
}
2020
return sum;
2121
};
22+
23+
// another
24+
25+
/**
26+
* @param {number} n
27+
* @return {number}
28+
*/
29+
const countVowelStrings = function (n) {
30+
const dp = Array.from({ length: n + 1 }, () => Array(5))
31+
recur(n, 0)
32+
return dp[n][0]
33+
function recur(r, i) {
34+
if(r === 0) return 1
35+
if(i === 5) return 0
36+
if(dp[r][i] != null) return dp[r][i]
37+
let res = recur(r, i + 1)
38+
res += recur(r - 1, i)
39+
return dp[r][i] = res
40+
}
41+
};

0 commit comments

Comments
 (0)