题解 | #把数字翻译成字符串#
把数字翻译成字符串
https://www.nowcoder.com/practice/046a55e6cd274cffb88fc32dba695668
class Solution: def solve(self, nums: str) -> int: n = len(nums) if n == 0: return 0 dp = [0] * (n + 1) dp[0] = 1 dp[1] = 1 if nums[0] != "0" else 0 for i in range(2, n + 1): if nums[i - 1] != "0": dp[i] += dp[i - 1] if "10" <= nums[i - 2 : i] <= "26": dp[i] += dp[i - 2] return dp[n]