题目:

思路:设置两个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. (转)WEB第三方打印控件[ASP.NET常用工具]

    本文转载自:http://blog.csdn.net/chz_cslg/article/details/25415347 在B/S模式开发中,打印是个很大的困扰.无论是采用页面直接输出或者引用WORD ...

  2. android学习笔记27——Activity

    Activity配置==> android应用程序要求所有的应用程序组件都需要进行显示配置后,才可正常使用.包括:Activity.Service.BroadCastReceiver.Conte ...

  3. Android AVD创建及设置中各参数详解

    设置AVD时有些参数比较模糊,特地找了篇文章,大家参考下! 本文根据如下的模拟器安装做一些解释: Name:自定义虚拟的名称,不能有空格或者其他非法字符,否则不能创建,即Creat AVD不能高亮点击 ...

  4. php获取从百度搜索进入网站的关键词

    <?php function search_word_from() { $referer = isset($_SERVER['HTTP_REFERER'])?$_SERVER['HTTP_REF ...

  5. windows初始化后做了哪些事情

    保护视力,将WINDOWS背景色变成淡绿色 绿色和蓝色对眼睛最好,建议大家在长时间用电脑后,经常看看蓝天.绿地,就能在一定程度上缓解视疲劳.同样的道理,如果我们把电脑屏幕和网页的底色变为淡淡的苹果绿, ...

  6. 8. redis的主从复制和sentinal

    一. redis主从复制(读写分离) redis的主从复制分为两类节点:1个master和多个slave,master进行读写操作,slav进行只读操作 启动步骤: 主节点照常启动,slave节点启动 ...

  7. C/C++代码静态分析插件 SourceInsight_Scan

    sourceinsight-scan 是一款集成在 SourceInsight 中的c/c++代码静态分析插件,集成了cppcheck,coverity,pclint等业界优秀的静态分析工具的优点. ...

  8. Python中HTTPS连接

    permike 原文 Python中HTTPS连接 今天写代码时碰到一个问题,花了几个小时的时间google, 首先需要安装openssl,更新到最新版本后,在浏览器里看是否可访问,如果是可以的,所以 ...

  9. php 消息队列

    本消息队列用于linux下,进程通信 #根据路径和后缀创建一个id $key = ftok(__DIR__, 'R'); #获取队列中的消息 $q = msg_get_queue($key); #删除 ...

  10. 树莓派3上安装Qt5

    按照在2上的安装只安装了qt4,实际上qt5已经可以直接apt方式可以获取到树莓派上了. install qt5-default and qtcreator:$ sudo apt-get instal ...