讨论/《图解算法数据结构》 - 剑指 Offer 46. 把数字翻译成字符串/
《图解算法数据结构》 - 剑指 Offer 46. 把数字翻译成字符串

c++

class Solution {
public:
    int translateNum(int num) 
    {
        int pre = 1;
        int last = 1;
        int y = num % 10;
        int x;
        int temp;
        int res;
        while(num > 9)
        {
            num /= 10;
            x = num % 10;
            temp = 10*x+y;
            res = temp >= 10 && temp <= 25 ? pre+last:pre;
            last = pre;
            pre = res;
            y = x;
        }
        return pre;   
    }
};
展开全部 10 讨论