?个人主页:Lei宝啊?
愿所有美好如期而遇
本题使用递归,该题不做解释
class Solution {
public:
string str[10] = {"","","abc","def","ghi","jkl",
"mno","pqrs","tuv","wxyz"};
void Conbine(vector<string>& vs, string& digits, int di, string Cbstr)
{
if(di == digits.size())
{
vs.push_back(Cbstr);
return;
}
int num = digits[di] - '0';
for(int i=0; i<str[num].size(); i++)
{
Conbine(vs, digits, di+1, Cbstr+str[num][i]);
}
}
vector<string> letterCombinations(string digits)
{
vector<string> vs;
if(digits == "")
return vs;
int di = 0;
Conbine(vs, digits, di, "");
return vs;
}
};