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 4a54264 commit 5fc8bd8Copy full SHA for 5fc8bd8
91-decode-ways.js
@@ -1,3 +1,27 @@
1
+/**
2
+ * @param {string} s
3
+ * @return {number}
4
+ */
5
+const numDecodings = function(s) {
6
+ if(s == null || s.length === 0) return 1
7
+ if(s[0] === '0') return 0
8
+ const set = new Set()
9
+ const n = s.length
10
+ for(let i = 1; i <= 26; i++) {
11
+ set.add(`${i}`)
12
+ }
13
+ const dp = Array(n + 1).fill(0)
14
+ dp[0] = dp[1] = 1
15
+ for(let i = 2; i <= n; i++) {
16
+ if(set.has(s[i - 2] + s[i - 1])) dp[i] += dp[i - 2]
17
+ if(set.has(s[i - 1])) dp[i] += dp[i - 1]
18
19
+ return dp[n]
20
+};
21
+
22
23
+// another
24
25
/**
26
* @param {string} s
27
* @return {number}
0 commit comments