17. Letter Combinations of a Phone Number
Posted ymjyqsx
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了17. Letter Combinations of a Phone Number相关的知识,希望对你有一定的参考价值。
https://www.cnblogs.com/grandyang/p/4452220.html
用迭代的方法,每次从3个字符中选择一个然后传给下一次迭代
class Solution { public: vector<string> letterCombinations(string digits) { vector<string> output; if(digits.empty()) return output; string dict[] = {"", "", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"}; combination(digits,dict,0,"",output); return output; } void combination(string digits,string dict[],int index,string input,vector<string> &output){ if(index == digits.size()){ output.push_back(input); return; } string str = dict[digits[index] - ‘0‘]; for(int i = 0;i < str.size();i++) combination(digits,dict,index+1,input + str[i],output); } };
以上是关于17. Letter Combinations of a Phone Number的主要内容,如果未能解决你的问题,请参考以下文章
17. Letter Combinations of a Phone Number
17. Letter Combinations of a Phone Number
17. Letter Combinations of a Phone Number
17. Letter Combinations of a Phone Number