Letter Combinations of a Phone Number
来源:互联网 发布:09外设淘宝店 编辑:程序博客网 时间:2024/05/16 09:12
Letter Combinations of a Phone Number
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.
Example:
Input:Digit string "23"Output: ["ad", "ae", "af", "bd", "be", "bf", "cd", "ce", "cf"].
Code:
class Solution {public: map<char,vector<char>> dict; vector<string> ret; void CreateDict() { dict.clear(); dict['2'].push_back('a'); dict['2'].push_back('b'); dict['2'].push_back('c'); dict['3'].push_back('d'); dict['3'].push_back('e'); dict['3'].push_back('f'); dict['4'].push_back('g'); dict['4'].push_back('h'); dict['4'].push_back('i'); dict['5'].push_back('j'); dict['5'].push_back('k'); dict['5'].push_back('l'); dict['6'].push_back('m'); dict['6'].push_back('n'); dict['6'].push_back('o'); dict['7'].push_back('p'); dict['7'].push_back('q'); dict['7'].push_back('r'); dict['7'].push_back('s'); dict['8'].push_back('t'); dict['8'].push_back('u'); dict['8'].push_back('v'); dict['9'].push_back('w'); dict['9'].push_back('x'); dict['9'].push_back('y'); dict['9'].push_back('z'); } void DFS(int curDep,int len,string &s,string ans) { if(curDep==len) { ret.push_back(ans); return ; } for(int i=0;i<dict[s[curDep]].size();i++) DFS(curDep+1,len,s,ans+dict[s[curDep]][i]); } vector<string> letterCombinations(string digits) { ret.clear(); CreateDict(); DFS(0,digits.size(),digits,""); 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
- 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
- Linux下MySQL慢查询分析mysqlsla安装使用
- @Repository、@Service、@Controller 和 @Component
- 效果好的好的就发现就发现就发现继发性
- eclipse中的maven插件无法下载jar包源码
- [紧急求助] LM317可调式直流稳压源输出电压不稳
- Letter Combinations of a Phone Number
- 仓成科形媳量耗聘锥舶
- 【cocos2dx-3.2】菜鸟之路——环境配置若干问题
- oracle点滴积累
- 说春陌押尤谙滋艘路百
- 发挥发挥的话的好的好的好的
- [Python]解决正则表达式的"贪婪"匹配
- C语言上机测试题 递归倒序输出字符串
- struts1.x执行指定方法 问题