num encodings

🏠
 1 class Solution:
 2     def numDecodings(self, s):
 3         if not s:
 4             return 0
 5 
 6         dp = [1] + [int(0 < int(s[0]) <= 9)] + [0] * (len(s) - 1)
 7 
 8         for i in range(2, len(s) + 1):
 9             sub1 = s[i - 1 : i]
10             sub2 = s[i - 2 : i]
11             dp[i] += dp[i - 1] if int(sub1) != 0 else 0
12             if sub2[0] != "0" and int(sub2) <= 26:
13                 dp[i] += dp[i - 2]
14         return dp[len(s)]
15 
16 
17 s = Solution().numDecodings("9371597631128776948387197132267188677349946742344217846154932859125134924241649584251978418763151253")
18 
19 print(s)