Advertisement
smj007

Untitled

Feb 17th, 2024
966
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.35 KB | None | 0 0
  1. class Solution:
  2.     def numDecodings(self, s: str) -> int:
  3.  
  4.         n = len(s)
  5.         dp = [0]*(n+1)
  6.         dp[0] = 1
  7.  
  8.         for i in range(1, n+1):
  9.             for j in range(1, 27):
  10.                 c = str(j)
  11.                 if i-len(c)>=0 and c == s[i-len(c):i]:
  12.                     dp[i] += dp[i-len(c)]
  13.  
  14.         return dp[-1]
  15.        
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement