深度优先搜索
class Solution {
public:
vector<string>ans;
string strs[10]={
"","","abc","def",
"ghi","jkl","mno",
"pqrs","tuv","wxyz"
};
vector<string> letterCombinations(string digits) {
if(digits.empty())return ans;
dfs(digits,0,"");
return ans;
}
void dfs(string &digits,int u,string path){ //u表示当前遍历到了第几位,path表示当前的方案
if(u==digits.size())ans.push_back(path);
else{
for(auto c:strs[digits[u]-'0']){
dfs(digits,u+1,path+c);
}
}
}
};
//dfs