[?*]Letter Combinations of a Phone Number
2015-11-17 08:08
411 查看
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.
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"].
public class Solution { public static List<String> letterCombinations(String digits) { String digitletter[] = {"","","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"}; List<String> result = new ArrayList<String>(); if (digits.length()==0) return result; result.add(""); for (int i=0; i<digits.length(); i++) result = combine(digitletter[digits.charAt(i)-'0'],result); return result; } public static List<String> combine(String digit, List<String> list) { List<String> result = new ArrayList<String>(); for (int i=0; i<digit.length(); i++) for (String x : list) result.add(x+digit.charAt(i)); return result; } }
相关文章推荐
- Android实现微信录制小视频的计时动画
- 我是这样看搜狗搜索与知乎合作的
- OC中的protocol
- 我的个人知识管理工具一览及相关经验技巧
- 技能的十一个级别
- 一步步教你Hadoop多节点集群安装配置
- 《你必须知道的495个C语言问题》知识笔记及补充
- Python篇----正则表达式语法(基础)
- mysql约束
- 三、jQuery事件处理
- 出发吧
- FileInputStream FileOutputStream
- 信号驱动式I/O模型,以终端I/O为例写个demo
- 操作系统进程调度之多级反馈队列算法模拟实现
- MySQL重要但容易被忽略_MySQL自定义函数&存储过程
- CSS图片选择
- 20151116小问题
- 解决百度地图找不到SDKInitializer,无法解析的问题
- OSChina 周二乱弹 —— 上班被老板碰瓷
- 5.6.3 投影和均匀裁剪空间