Skip to content

Commit c5c8548

Browse files
committed
decode-ways solution
1 parent 53a3fd3 commit c5c8548

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

decode-ways/yayyz.py

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

0 commit comments

Comments
 (0)