一、题目
二、思路
1、dfs深度优先所搜解决,遍历树的每一个分支
2、递归,给出退出递归的条件,以及每一个子问题的解决方法
三、代码
class Solution {
public:
vector<string>Info{"abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};
vector<string>Output;
vector<string> letterCombinations(string digits) {
if(digits.empty())
{
return Output;
}
string str="";
int res=0;
dfs(digits,res,str);
return Output;
}
void dfs(string &digit,int res,string str)
{
if(res==digit.length())
{
Output.emplace_back(str);
//str=str.substr(0,str.length()-1);
return;
}
for(int i=0;i<Info[digit[res]-'0'-2].length();++i)
{
//str+=Info[digit[res]-'0'-2][i];
dfs(digit,res+1,str+Info[digit[res]-'0'-2][i]);
}
}
};