题目链接:17. 电话号码的字母组合 - 力扣(LeetCode)
思路:每一个数字对应的每一个字母一 一组合。
具体细节看以下递归图:
参考代码:
class Solution { public: string str[10]={"","","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"}; vector<string>& _letterCombinations(vector<string>& strV,const string& digits,int i, string combinStr) { if(i==digits.size()) { strV.push_back(combinStr); return strV; } string a=str[digits[i]-'0']; int j=0; for(j=0;j<a.size();j++) { _letterCombinations(strV,digits,i+1,combinStr+a[j]); } return strV; } vector<string> letterCombinations(string digits) { vector<string> strV; string combinStr; if(digits.empty()) { return strV; } return _letterCombinations(strV,digits,0,combinStr); } };