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 af374c9 commit 54f5602Copy full SHA for 54f5602
decode-ways/seungseung88.js
@@ -0,0 +1,26 @@
1
+/**
2
+ * 시간 복잡도: O(n)
3
+ * 공간 복잡도: O(n)
4
+ */
5
+var numDecodings = function (s) {
6
+ const memo = new Map();
7
+ memo.set(s.length, 1);
8
+
9
+ function dfs(start) {
10
+ if (memo.has(start)) {
11
+ return memo.get(start);
12
+ }
13
14
+ if (s[start] === '0') {
15
+ memo.set(start, 0);
16
+ } else if (start + 1 < s.length && parseInt(s.slice(start, start + 2)) < 27) {
17
+ memo.set(start, dfs(start + 1) + dfs(start + 2));
18
+ } else {
19
+ memo.set(start, dfs(start + 1));
20
21
22
23
24
25
+ dfs(0);
26
+};
0 commit comments