LeetCode: Letter Combinations of a Phone Number
来源:互联网 发布:java fix 编辑:程序博客网 时间:2024/05/21 09:22
思路:递归求解,为求当前的str表示的字符串,可以先求出str[1]开始的子串数字能够表示的字符串。然后再将str[0]指示的字符依次贴到这些字符串中,得到最终解。
code:
class Solution {public: vector<string> letterCombinations(string digits) { string word[] = {" ","","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"}; vector<string> ret; int digitLen = digits.length(); if(digitLen>0){ int len = word[digits[0] -'0'].length(); string subDigits = digits.substr(1,digitLen-1); vector<string> subRet; subRet = letterCombinations(subDigits); int subLen = subRet.size(); for(int i=0;i<len;i++){ for(int j=0;j<subLen;j++){ string str = word[digits[0] -'0'][i] + subRet[j]; ret.push_back(str); } } } else ret.push_back(""); return ret; }};
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
- 【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
- 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
- 【leetcode】Letter Combinations of a Phone Number
- [LeetCode] Letter Combinations of a Phone Number
- leetcode: Letter Combinations of a Phone Number
- Google为什么赢得了搜索引擎大战
- UVa 10061 - How many zero's and how many digits ?
- sysfs文件系统注册-sysfs_init()
- 69_leetcode_Binary Tree Level Order Traversal
- LinearLayout和RelativeLayout 属性对比
- LeetCode: Letter Combinations of a Phone Number
- dfs
- 在Delphi环境下基于SPCOMM控件开发串口通讯报文字节丢失的问题解决
- SSI (Server Side Include) in one page
- Apache和tomcat的区别
- 艾非
- POJ 3468 A Simple Problem with Integers 线段树
- Spring HandlerInterceptor的使用
- flash builder语言设置