题目链接:https://leetcode-cn.com/problems/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof/
难度:中等
描述:
给定一个数字,我们按照如下规则把它翻译为字符串:0 翻译成 “a” ,1 翻译成 “b”,……,11 翻译成 “l”,……,25 翻译成 “z”。一个数字可能有多个翻译。请编程实现一个函数,用来计算一个数字有多少种不同的翻译方法。
题解
class Solution:def translateNum(self, num: int) -> int:a, b = 1, 1x = num % 10while num != 0:num //= 10y = num % 10a, b = (a+b if 10 <= 10 * y + x <= 25 else a), ax = yreturn a
