题目:

思路:设置两个List,一个存储当前层,一个存储最终层

public class Solution {
public List<String> letterCombinations(String digits) {
List<String> listRet=new ArrayList<String>();
if(digits==""){
return listRet;
}
Map<Character,String> map=new HashMap<Character,String>();
map.put('0',"0");
map.put('1',"1");
map.put('2',"abc");
map.put('3',"def");
map.put('4',"ghi");
map.put('5',"jkl");
map.put('6',"mno");
map.put('7',"pqrs");
map.put('8',"tuv");
map.put('9',"wxyz"); for(int i=0;i<digits.length();i++){
List<String> listTem=new ArrayList<String>();
if(i==0){
char[] initials=map.get(digits.charAt(0)).toCharArray();
for(char initial:initials){
listRet.add(String.valueOf(initial));
}
continue;
}
String s1=map.get(digits.charAt(i));
char[] letters=s1.toCharArray();//当前数字对应字符串
for(char letter:letters){
for(String pre:listRet){
listTem.add(pre+String.valueOf(letter));//前缀+当前层字符
}
}
listRet=listTem;
}
return listRet;
}
}

  

【LeetCode】17. Letter Combinations of a Phone Number的更多相关文章

  1. 【LeetCode】17. Letter Combinations of a Phone Number 电话号码的字母组合

    作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 个人公众号:负雪明烛 本文关键词:电话号码, 字母组合,回溯法,题解,leetcode, ...

  2. 【一天一道LeetCode】#17. Letter Combinations of a Phone Number

    一天一道LeetCode (一)题目 Given a digit string, return all possible letter combinations that the number cou ...

  3. 【LeetCode】017. Letter Combinations of a Phone Number

    题目: Given a digit string, return all possible letter combinations that the number could represent. A ...

  4. [LeetCode][Python]17: Letter Combinations of a Phone Number

    # -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 17: Letter Combinations of a Phone Numb ...

  5. 《LeetBook》leetcode题解(17):Letter Combinations of a Phone Number[M]

    我现在在做一个叫<leetbook>的免费开源书项目,力求提供最易懂的中文思路,目前把解题思路都同步更新到gitbook上了,需要的同学可以去看看 书的地址:https://hk029.g ...

  6. LeetCode:17. Letter Combinations of a Phone Number(Medium)

    1. 原题链接 https://leetcode.com/problems/letter-combinations-of-a-phone-number/description/ 2. 题目要求 给定一 ...

  7. Leetcode 17. Letter Combinations of a Phone Number(水)

    17. Letter Combinations of a Phone Number Medium Given a string containing digits from 2-9 inclusive ...

  8. 刷题17. Letter Combinations of a Phone Number

    一.题目说明 题目17. Letter Combinations of a Phone Number,题目给了下面一个图,输入一个字符串包括2-9,输出所有可能的字符组合. 如输入23所有可能的输出: ...

  9. [LeetCode] 17. Letter Combinations of a Phone Number 电话号码的字母组合

    Given a string containing digits from 2-9inclusive, return all possible letter combinations that the ...

随机推荐

  1. 【转】8张图理解Java

    一图胜千言,下面图解均来自Program Creek 网站的Java教程,目前它们拥有最多的票选.如果图解没有阐明问题,那么你可以借助它的标题来一窥究竟. 1.字符串不变性 下面这张图展示了这段代码做 ...

  2. gdb: multiple process debug

    gdbserver自身不支持multiple process:如果你调试parent process时在子进程上下断点,子进程在运行到那个断点时就会SIGTRAP. 如果你要调试fork出来的子进程: ...

  3. 【springBoot】springBoot返回json的一个问题

    首先看下面的代码 @Controller @RequestMapping("/users") public class UserController { @RequestMappi ...

  4. 安装ORACLE后,改变计算机名称,导致OracleDBConsoleOrcl服务无法启动

    错误信息: 启动oracledbconsoleorcl 服务提示 -- “--Windows不能再本地计算机启动oracledbconsoleorcl  有关更多信息,查阅系统事件日志,如果这是非Mi ...

  5. C#中的 int?是什么意思

    http://www.cnblogs.com/firstcsharp/archive/2011/12/11/2283797.html int?:表示可空类型,就是一种特殊的值类型,它的值可以为null ...

  6. ADF_General JSF系列2_创建JSF类型的页面向导

    2015-02-17 Created By BaoXinjian

  7. DBA_在Linux上安装Oracle Database11g数据库(案例)

    2014-08-08 Created By BaoXinjian

  8. python (18)在linux中如何实现定时发送邮件

    最近要用到,定时发送邮件功能: 如何定时,当然要用到linux中crontab了 如下的代码能够定时发送邮件 #!/usr/bin/env python # -*- coding=utf-8 -*- ...

  9. Coding 初级教程(二)——上传已有项目

    Coding 初级教程(二)——上传已有项目 [摘要:方针读者 :已具有 Coding.net 的账号. 本文首要先容若何把项目上传到 Coding.net 上. 分两种环境,一种是项目已归入到 gi ...

  10. heredoc和nowdoc的区别

    heredoc使用 <<< EOT 的标示符,而nowdoc使用 <<< 'EOT' 这样的标示符,其中nowdoc是PHP5.3引进的新技术,它包含了heredo ...