Letter Combinations of a Phone Number

发布时间:2016-12-7 5:47:58 编辑:www.fx114.net 分享查询网我要评论
本篇文章主要介绍了"Letter Combinations of a Phone Number",主要涉及到Letter Combinations of a Phone Number方面的内容,对于Letter Combinations of a Phone Number感兴趣的同学可以参考一下。

class Solution {/*Straightforward, and easy**/ private: vector<string> rep; vector<string> result; void build(const string & digits, int digitIndex, string ss) { int num = digits[digitIndex]-'0'; if (digitIndex + 1 == digits.length()) { for(int buttonIndex = 0; buttonIndex < rep[num].length(); ++buttonIndex) { result.push_back(ss+rep[num][buttonIndex]); } return; } for(int buttonIndex = 0; buttonIndex < rep[num].length(); ++buttonIndex) { build(digits, digitIndex+1,ss+rep[num][buttonIndex]); } return; } public: vector<string> letterCombinations(string digits) { // Start typing your C/C++ solution below // DO NOT write int main() function if (digits.empty()) return vector<string>(1,""); result.clear(); rep.resize(10); rep[2]="abc"; rep[3]="def"; rep[4]="ghi"; rep[5]="jkl"; rep[6]="mno"; rep[7]="pqrs"; rep[8]="tuv"; rep[9]="wxyz"; build(digits, 0, ""); return result; } };   DFS 题目

上一篇:JAVA net之TCP
下一篇:poj 1755 Triathlon(半平面交解不等式)

相关文章

相关评论