class Solution {
public:
string s = "";
vector<string>aa;
vector<string>ying{ "===", "---", "abc", "def", "ghi",
"jkl", "mno", "pqrs", "tuv", "wxyz" };
vector<string> letterCombinations(string digits) {
if (digits.empty())
return {};
dfs(digits, 0, s);
return aa;
}
int dfs(string digits, int i, string s)
{
if (i > digits.size() - 1)
{
aa.push_back(s);
return 0;
}
if (digits[i]=='7'||digits[i]=='9')
for (int k = 0; k < 4; k++)
{
dfs(digits, i + 1, s + ying[digits[i] - '0'][k]);//递归这样子才能对S进行去栈
//另外注意digits[i]返回的是字符不是数字
}
else
for (int j = 0; j < 3; j++)
{
dfs(digits, i + 1, s + ying[digits[i] - '0'][j]);
}
return 0;
}
};
17. 电话号码的字母组合
最新推荐文章于 2023-08-25 12:20:00 发布