Skip to content

Commit cf50f90

Browse files
committed
feat: add decode ways solution
1 parent 8771f03 commit cf50f90

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

decode-ways/mangodm-web.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Solution:
2+
def numDecodings(self, s: str) -> int:
3+
if s[0] == "0":
4+
return 0
5+
6+
n = len(s)
7+
dp = [0] * (n + 1)
8+
dp[0], dp[1] = 1, 1
9+
10+
for i in range(2, n + 1):
11+
if s[i - 1] != "0":
12+
dp[i] += dp[i - 1]
13+
if "10" <= s[i - 2 : i] <= "26":
14+
dp[i] += dp[i - 2]
15+
16+
return dp[n]

0 commit comments

Comments
 (0)