We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 3ad73ad commit bd42bfbCopy full SHA for bd42bfb
decode-ways/casentino.ts
@@ -0,0 +1,21 @@
1
+function numDecodings(s: string): number {
2
+ if (s.length === 1 && s[0] !== "0") {
3
+ return 1;
4
+ }
5
+ if (s[0] === "0") {
6
+ return 0;
7
8
+ const dp = new Array(s.length + 1).fill(0);
9
+ dp[0] = 1;
10
+ dp[1] = 1;
11
+ for (let i = 2; i <= s.length; i++) {
12
+ if (s[i - 1] !== "0") {
13
+ dp[i] += dp[i - 1];
14
15
+ const doubleNum = parseInt(s[i - 2] + s[i - 1]);
16
+ if (doubleNum >= 10 && doubleNum <= 26) {
17
+ dp[i] += dp[i - 2];
18
19
20
+ return dp[s.length];
21
+}
0 commit comments