题目描述:
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;
}
};