Skip to content

Commit 01af7f3

Browse files
committed
Added Count Sorted Vowel Strings.java
1 parent 89ff1f4 commit 01af7f3

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Solution {
2+
public int countVowelStrings(int n) {
3+
Integer[][] memo = new Integer[n + 1][5];
4+
return topDownDP(n, 0, memo);
5+
}
6+
7+
private int topDownDP(int n, int idx, Integer[][] memo) {
8+
if (n == 0) {
9+
return 1;
10+
} else if (idx == 5) {
11+
return 0;
12+
} else if (memo[n][idx] != null) {
13+
return memo[n][idx];
14+
}
15+
int numOfPermutations = topDownDP(n, idx + 1, memo);
16+
numOfPermutations += topDownDP(n - 1, idx, memo);
17+
return memo[n][idx] = numOfPermutations;
18+
}
19+
}

0 commit comments

Comments
 (0)