Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ceecd45

Browse files
committed
Day79
1 parent aa6b615 commit ceecd45

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

Day79/index.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* @param {string} s
3+
* @return {number}
4+
*/
5+
var numDecodings = function (s) {
6+
7+
8+
9+
let dp = new Array(s.length + 1).fill(0);
10+
11+
dp[0] = 1; //empty steriung
12+
13+
dp[1] = s.charAt(0) == 0 ? 0 : 1;
14+
15+
for (let i = 2; i <= s.length; i++) {
16+
let oneDigit = +s.slice(i - 1, i);
17+
let twoDigit = +s.slice(i - 2, i);
18+
if (oneDigit >= 1) {
19+
dp[i] += dp[i - 1]
20+
}
21+
if (twoDigit >= 10 && twoDigit <= 26) {
22+
dp[i] += dp[i - 2]
23+
}
24+
}
25+
26+
return dp[s.length]
27+
};

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,4 +176,6 @@ If you are loving solving problems in leetcode, please contact me to enjoy it to
176176

177177
|Day 77| [24. Swap Nodes in Pairs](https://leetcode.com/problems/swap-nodes-in-pairs/) | [javascript]()|[:memo:](https://leetcode.com/problems/swap-nodes-in-pairs/)|Medium|
178178

179-
|Day 78| [498. Diagonal Traverse](https://leetcode.com/problems/diagonal-traverse/) | [javascript]()|[:memo:](https://leetcode.com/problems/diagonal-traverse/)|Medium|
179+
|Day 78| [498. Diagonal Traverse](https://leetcode.com/problems/diagonal-traverse/) | [javascript]()|[:memo:](https://leetcode.com/problems/diagonal-traverse/)|Medium|
180+
181+
|Day 79| [91. Decode Ways](https://leetcode.com/problems/decode-ways/) | [javascript]()|[:memo:](https://leetcode.com/problems/decode-ways/)|Medium|

0 commit comments

Comments
 (0)