解题关键点:用递归方法
class Solution { public: vector<string> mapping = { "abc","def","ghi","jkl", "mno","pqrs","tuv","wxyz"}; void combinations(string digits, int idx, string str, vector<string>& result) { if (idx == digits.size()) { result.push_back(str); return; } string chars = mapping[digits[idx]-'2']; for (int i = 0; i < chars.size(); i++) { combinations(digits,idx+1,str+chars[i],result); } } public: vector<string> letterCombinations(string digits) { vector<string> result; if (digits.size() == 0) return result; combinations(digits,0,"",result); return result; } };
标签:digits,return,17,idx,vector,result,字母组合,leetcode,string From: https://www.cnblogs.com/repinkply/p/18015580