题目描述:

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.

解题思路:

递归法解题之。从第一个字符串开始确认结果,然后递归地确认余下各项结果。

参考博客:http://blog.csdn.net/china_wanglong/article/details/38495355

代码如下:

public class Solution {
public List<String> letterCombinations(String digits) {
List<String> result = new ArrayList<String>();
String[] map = new String[] { "", "", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz" };
char[] tmp = new char[digits.length()];
if(digits.length() == 0)
return result;
rec(digits, 0, tmp, map, result);
return result;
}
public void rec(String digits, int index, char[] tmp, String[] map, List<String> result){
if(index == digits.length()){
result.add(new String(tmp));
return;
}
char tmpChar = digits.charAt(index);
for(int i = 0; i < map[tmpChar - '0'].length(); i++){
tmp[index] = map[tmpChar - '0'].charAt(i);
rec(digits, index + 1, tmp, map, result);
}
}
}

Java [leetcode 17]Letter Combinations of a Phone Number的更多相关文章

  1. 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 ...

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

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

  3. [leetcode 17]Letter Combinations of a Phone Number

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

  4. Leetcode 17.——Letter Combinations of a Phone Number

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

  5. [leetcode]17. Letter Combinations of a Phone Number手机键盘的字母组合

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

  6. [LeetCode] 17. Letter Combinations of a Phone Number ☆☆

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

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

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

  8. LeetCode 17 Letter Combinations of a Phone Number (电话号码字符组合)

    题目链接 https://leetcode.com/problems/letter-combinations-of-a-phone-number/?tab=Description HashMap< ...

  9. LeetCode——17. Letter Combinations of a Phone Number

    一.题目链接: https://leetcode.com/problems/letter-combinations-of-a-phone-number/ 二.题目大意: 给定一段数字字符串,其中每个数 ...

随机推荐

  1. Kinetic使用注意点--container

    <virtual> new Container(config) 参数: config:包含所有配置项的对象. { x: "横坐标", y: "纵坐标" ...

  2. java开发命名规范总结

    一 包名的书写规范 (Package)推荐使用公司或机构的顶级域名为包名的前缀,目的是保证各公司/机构内所使用的包名的唯一性.包名全部为小写字母,且具有实际的区分意义. 1.1 一般要求1.选择有意义 ...

  3. 【学习总结】UIGestureRecognizer(手势识别器)

    基本知识点 : -> IOS 3.2之后 , 苹果推出了手势识别功能 ( Gesture Recognizer ) 在触摸事件处理方面 , 简化开发难度. -> UIGesture Rec ...

  4. Java注解处理器(转)

    Java中的注解(Annotation)是一个很神奇的东西,特别现在有很多Android库都是使用注解的方式来实现的.一直想详细了解一下其中的原理.很有幸阅读到一篇详细解释编写注解处理器的文章.本文的 ...

  5. 第一个js库文件

    <!DOCTYPE html> <html xmlns=;         ;                     }                 };     })(); ...

  6. kill 进程卡住,超时kill方法

    还是有漏洞 ,万一 working.py未超时, kill_job.sh 会不会杀死别人的进程啊start.sh#!/bin/bash python working.py &python wo ...

  7. Linux下Nginx+Tomcat整合的安装与配置

    因为nginx处理静态页面的速度很快,并且是免费的,它还可以配置负载均衡的服务器集群来搭建多个tomcat,所以nginx+tomcat是企业搭 建javaee项目很好的选择.nginx主要是通过反向 ...

  8. the service mysql56 was not found in the Windows services的解决办法

    mysql无法启动,无法改变状态-CSDN论坛-CSDN.NET-中国最大的IT技术社区 http://bbs.csdn.net/topics/390943788   具体描述: 关闭,重启mysql ...

  9. ARMv7 .n和.w指令宽度指示符后缀

    Thumb code里,.n后缀强迫生成16bit的代码,即Thumb code,若是在arm code里用.n会报错,若是机器指令没有办法用16表示也会报错 Thumb code里,.w后缀强迫生成 ...

  10. Linux下执行程序出现 Text file busy 提示时的处理方式

    使用 fuser xxx 命令查看xxx文件被哪个进程占用,然后关闭该进程,解决问题. # fuser xxxxxx:              2878# kill -9 2878 注:xxx是文件 ...