Letter Combinations of a Phone Number
2013-09-03 16:32
363 查看
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 题目
相关文章推荐
- Letter Combinations of a Phone Number
- 【Leetcode】【python】Letter Combinations of a Phone Number
- [LeetCode]Letter Combinations of a Phone Number
- Letter Combinations of a Phone Number 解法
- [leetcode]Letter Combinations of a Phone Number
- Letter Combinations of a Phone Number
- Letter Combinations of a Phone Number
- [LeetCode]Letter Combinations of a Phone Number
- Letter Combinations of a Phone Number
- Letter Combinations of a Phone Number
- LeetCode17:Letter Combinations of a Phone Number
- Letter Combinations of a Phone Number
- 17. Letter Combinations of a Phone Number
- LeetCode: Letter Combinations of a Phone Number
- [?*]Letter Combinations of a Phone Number
- LeetCode OJ - Letter Combinations of a Phone Number
- 17. Letter Combinations of a Phone Number
- Letter Combinations of a Phone Number
- Letter Combinations of a Phone Number--LeetCode
- leetcode-17 Letter Combinations of a Phone Number