string a[] = {
{" "},
{" "},
{"abc"},
{"def"},
{"ghi"},
{"jkl"},
{"mon"},
{"pqrs"},
{"tuv"},
{"wxyz"}
};
vector<string> res;
class Solution {
public:
vector<string> letterCombinations(string digits) {
res.clear();
if (digits.size() == 0)
return res;
else
{
string s = "";
dfs(digits, 0, s);
return res;
}
}
void dfs(string digits, int index, string s)
{
if (index >= digits.size())
{
res.push_back(s);
return;
}
for (int i = index; i < digits.size(); i++)
{
int m = digits[i] - '0';
for (int j = 0; j < a[m].size(); j++)
{
s += a[m][j];
dfs(digits, index+1,s);
s.replace(s.size() - 1, 1, "");
}
}
}
};