class Solution {
public:
string path;
vector<string> result;
vector<string> letterCombinations(string digits) {
if(digits.size()==0) return result;
traverse(digits,0);
return result;
}
void traverse(string digits, int index){
if(index==digits.size()){
result.push_back(path);
return;
}
int rep_num;
if(digits[index]=='7'||digits[index]=='9')
rep_num=4;
else
rep_num=3;
for(int i=0;i<rep_num;i++){
if(digits[index]=='8'||digits[index]=='9')
path.push_back('a'+i+(digits[index]-'2')*3+1);
else
path.push_back('a'+i+(digits[index]-'2')*3);
traverse(digits, index+1);
path.pop_back();
}
}
};
刷题记录第八十六天-电话号码的字母组合
最新推荐文章于 2024-08-24 17:09:16 发布