Given a string containing digits from 2-9 inclusive, 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. Note that 1 does not map to any letters.

Example:

Input: "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.

 class Solution {
public List<String> letterCombinations(String digits) {
LinkedList<String> res = new LinkedList<String>();
if(digits.isEmpty()) return res;
String[] mapping = new String[] {"0", "1", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
res.add("");
for(int i=0;i<digits.length();i++){
int x=Character.getNumericValue(digits.charAt(i));
while(res.peek().length()==i){
String t = res.remove();
for (char s :mapping[x].toCharArray())
res.add(t+s);
}
}
return res;
}
}

最新文章

  1. java的英文词频算法
  2. 使用winpcap多线程抓包,以及简单的分析数据包
  3. python公司面试题集锦 python面试题大全
  4. IPv6介绍
  5. (转)Java Ant build.xml详解
  6. [Protractor] Getting Started With Protractor
  7. asp.net MVC Razor 语法(2)
  8. PHP操作Mysql中间BLOB场
  9. 鸟哥Linux私房菜知识点总结6到7章
  10. JAVA-面向对象--封装
  11. RGB565的理解
  12. HttpStatus各种状态
  13. HDU 1317XYZZY spfa+判断正环+链式前向星(感觉不对,但能A)
  14. C# DropDownList 绑定枚举类
  15. easyui常见问题
  16. jQuery toastr提示简单实现
  17. hadoop集群无法找到datanode节点问题解决
  18. 目标检测算法之R-CNN算法详解
  19. div在页面垂直居中方法---增强改进版
  20. GIS中的数据库.gdb与.mdb的区别

热门文章

  1. [knowledge] netmap
  2. storm配置文件
  3. mysql存储过程游标嵌套循环
  4. 字符集更改步骤,mysql乱码
  5. 前端 html button标签
  6. 用laravel dingo/api创建简单的api
  7. 新辰:共享是SEO的思维 用户是SEO的核心
  8. Mysql索引详细语法
  9. H5-FileReader实现图片预览&amp;Ajax上传文件
  10. poi 生成图片到excel