专业做厂房的网站怎样和政府交换友链
题目链接:17. 电话号码的字母组合 - 力扣(LeetCode)
组合的过程是一个长树的过程,可以用深度遍历实现,每一个数字对应的字符串都是一层,一种字母组合就是一条路径,当递归的深度达到层数就找到了一种字母组合
class Solution {
public:string code[8] = {"abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};vector<string> ans;string digits;void dfs(string combine, int depth) {if (depth == digits.size())ans.push_back(std::move(combine));elsefor (auto &it: code[digits[depth] - '2'])dfs(combine + it, depth + 1);}vector<string> letterCombinations(string digits) {this->digits = digits;if (digits.size() == 0)return {};dfs("", 0);return ans;}
};