题解 | #把数字翻译成字符串#
把数字翻译成字符串
https://www.nowcoder.com/practice/046a55e6cd274cffb88fc32dba695668
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # 解码 # @param nums string字符串 数字串 # @return int整型 # class Solution: def solve(self , nums: str) -> int: # write code n = len(nums) dp = [0]*(n+1) dp[0] = 1 for i in range(1,n+1): if nums[i-1] != '0': dp[i] += dp[i-1] if i-2>=0 and nums[i-2]!='0' and 1<=int(nums[i-2])*10 + int(nums[i-1])<=26 : dp[i] += dp[i-2] return dp[n]