MCPcopy Create free account
hub / github.com/codedecks-in/LeetCode-Solutions / numDecodings

Method numDecodings

Python/decode-ways.py:7–20  ·  view source on GitHub ↗
(self, s: str)

Source from the content-addressed store, hash-verified

5'''
6class Solution:
7 def numDecodings(self, s: str) -> int:
8 if not s or s[0]=='0':
9 return 0
10 dp = [0]*(len(s)+1)
11 dp[0],dp[1] = 1,1
12 for j in range(2,len(s)+1):
13 i = j-1
14 a = int(s[i])
15 b = int(s[i-1:i+1])
16 if 0<a<10:
17 dp[j]=dp[j-1]
18 if s[i-1]!='0' and 0<b<27:
19 dp[j]+=dp[j-2]
20 return dp[-1]
21
22
23##Improved

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected