Letter Combinations of a Phone Number
来源:互联网 发布:winscp网络错误被拒绝 编辑:程序博客网 时间:2024/06/08 18:33
问题:链接
Given a digit string, return all possible letter combinations that the number could represent.
A mapping of digit to letters (just like on the telephone buttons) is given below.
Input:Digit string "23"Output: ["ad", "ae", "af", "bd", "be", "bf", "cd", "ce", "cf"].
Note:
Although the above answer is in lexicographical order, your answer could be in any order you want.
DFS
参考:http://www.cnblogs.com/Rosanna/p/3416949.html
代码:
class Solution {public: vector<string> letterCombinations(string digits) {string strlist[8] = {"abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"}; string result = ""; m_digits = digits;if(digits == ""){re_str.push_back("");return re_str;} if(digits.size() == 0) return re_str; print(result, 0, strlist); return re_str; } void print(string result, int i, string strlist[]) { int num = m_digits[i] - '0'; if(i < m_digits.size()) {for(int j = 0; j < strlist[num-2].size(); ++j){print(result + strlist[num-2][j], i+1, strlist);} } else { re_str.push_back(result); } }private: vector<string> re_str; string m_digits;};
0 0
- LeetCode: Letter Combinations of a Phone Number
- LeetCode Letter Combinations of a Phone Number
- LeetCode: Letter Combinations of a Phone Number
- [Leetcode] Letter Combinations of a Phone Number
- [LeetCode] Letter Combinations of a Phone Number
- LeetCode18:Letter Combinations of a Phone Number
- Letter Combinations of a Phone Number
- 【leetcode】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
- 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
- LeetCode - Letter Combinations of a Phone Number
- LeetCode:Letter Combinations of a Phone Number
- CentOS下rdesktop的安装与环境配置
- 甘睿星心得5
- linux apr安装
- android视图继承关系
- mfc欢迎页
- Letter Combinations of a Phone Number
- HDU 3308
- 全站GZIP压缩过滤器
- Java POI读取Office excel (2003,2007)及相关jar包
- Setting up a CloudStack dev environment on Windows
- Oracle SQL优化必要的全表扫描思路分析
- ctags为系统头文件目录生成tags
- Leetcode-Convert Sorted List to Binary Search Tree
- 基于有限自动机的KMP算法构造思想