17. Letter Combinations of a Phone Number LeetCode
来源:互联网 发布:季羡林的孩子知乎 编辑:程序博客网 时间:2024/05/29 10:53
题意:给出9键手机键盘和用户按的数字,求所有可能的字母组合,按字典序排列。
题解:把数字和字母用map存一下,然后dfs就可以。
class Solution {public: map<char,string>ma = {{'2',"abc"}, {'3',"def"}, {'4',"ghi"},{'5',"jkl"}, {'6',"mno"}, {'7',"pqrs"}, {'8',"tuv"}, {'9',"wxyz"}}; void dfs(vector<string>& ans,string pre,int k,string digits) { if(k == digits.length()) { ans.push_back(pre); return; } string tmp = ma[digits[k]]; for(int i = 0; i < tmp.length(); i++) dfs(ans,pre + tmp[i],k + 1,digits); } vector<string> letterCombinations(string digits) { vector<string> ans; ans.clear(); if(digits.length() == 0) return ans; dfs(ans,"",0,digits); return ans; }};
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
- JavaWeb不用选择结构直接引用资源文件
- Android性能优化系列
- JNI 实战全面解析
- liunx系统下 锐捷使用以及虚拟拨号教程
- Spring常用注解
- 17. Letter Combinations of a Phone Number LeetCode
- C++ 虚函数表解析
- maven生成web project,后转换为eclipse
- 《剑指Offer:名企面试官精讲典型编程题》一书中IT名企经典面试题
- 217. Contains Duplicate
- 计算1!+2!+.....+20!的和
- 第六章:JavaScript面向对象编程
- Android SVG 矢量动画机制
- JAVA 高级报表导出Excel