目录
一、题目
二、代码
一、题目
17. 电话号码的字母组合 - 力扣(LeetCode)
二、代码
class Solution {const char*data[10]={"","","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};
public:void Combination(string s,string str,int k,vector<string>&ret)//s是digits,str存放每个组合,k计数,ret存放所有结果{if(k==s.size())//结束条件{ret.push_back(str);return;}int nums=s[k]-'0';string sonStr=data[nums];for(auto ch:sonStr){Combination(s,str+ch,k+1,ret);}}vector<string> letterCombinations(string digits) {string str;vector<string>ret;if(digits.empty()){return ret;}Combination(digits,str,0,ret);return ret;}
};