[LeetCode] Letter Combinations of a Phone Number
来源:互联网 发布:mysql从零开始学 编辑:程序博客网 时间:2024/06/06 00:03
Total Accepted: 8862 Total Submissions: 34390
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.
public class Solution { public ArrayList<String> letterCombinations(String digits) { ArrayList<String> list = new ArrayList<String>(); char[][] keyMap = {{}, {'a','b','c'}, {'d','e','f'}, {'g','h','i'}, {'j','k','l'}, {'m','n','o'}, {'p','q','r','s'}, {'t','u','v'}, {'w','x','y','z'}}; dfs(list, "", digits, keyMap); return list; } public void dfs(ArrayList<String> list, String path, String digits, char[][] keyMap) { if (path.length() == digits.length()) { list.add(path); return; } else { int num = digits.charAt(path.length()) - '1'; for (int i = 0; i < keyMap[num].length; i++) { dfs(list, path + keyMap[num][i], digits, keyMap); } } } }
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
- 学习JavaMelody系统监控工具使用配置
- iOS7 UIWebView内存泄露问题解决方法
- 计算器之逆波兰算法
- Zend API: 支持初始化文件(php.ini)
- Qt的Linux 线程中传递,类的类型参数
- [LeetCode] Letter Combinations of a Phone Number
- 【Ubuntu】[VIM]:ubuntu下vi不能正常使用的解决方法
- python—xml读写—minidom and etree
- Opengl es2.0 glEnable(GL_TEXTURE_2D)报错 GL_INVALID_ENUM
- Sharepoint2013 Report Service初探
- 与android database 交互(chapter 14-Working with the SQLite Database)
- Spark安装启动 and 在程序中调用spark服务
- linux 查看 进程 端口号
- 树状数组解敌兵布阵