1309 LeetCode 解码字母到整数映射

题目描述:
LeetCode第1309 题 解码字母到整数映射
类型简单

思路:
倒叙遍历

代码如下:

class Solution {
public:
    string freqAlphabets(string s) {
        string res="";
        string letter[26]={"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"};
        int i=s.size()-1;
        while(i>=0){
            if(s[i]=='#'){
                int temp=(s[i-1]-'0')+10*(s[i-2]-'0');
                res=letter[temp-1]+res;
                i-=3;
            }
            else {
                int cur=s[i]-'0';
                res=letter[cur-1]+res;
                i--;
            }
        }
        return res;
    }
};
发布了224 篇原创文章 · 获赞 0 · 访问量 3127

猜你喜欢

转载自blog.csdn.net/peachzy/article/details/105006841