class Solution {
public:
vector<string> letterCombinations(string digits) {
map<int,string>imap;
vector<string>s={" ","","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};
string temp;
vector<string>result;
if(digits.empty()) return result;
int len=digits.size();
dfs(0,s,len,temp,result,digits);
return result;
}
void dfs(int i,vector<string> &s,int len,string &temp,vector<string>&result,string &digits) //不能加引用; int &i 和int &len;
{
if(i==len) { result.push_back(temp);
return;}
string s1=s[digits[i]-'0'];
for(int j=0;j<s1.size();j++)
{
temp+=s1[j];
dfs(i+1,s,len,temp,result,digits);
temp.pop_back();
}
}
};
非递归;