1 题目:

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.

2 思路

好吧,想了半天,想不出来,参考别人的。

当时想着就是怎么每次循环,再一个字符串后面加一个字符。

看到别人的代码,处理的很好。

https://leetcode.com/discuss/24431/my-java-solution-with-fifo-queue

主要在ans.peek().length()==i、String t= ans.remove、链表上。

3 代码:

仿别人代码做的。

    public List<String> letterCombinations(String digits)
{
String[] maps = {" ","1","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};
LinkedList<String> result = new LinkedList<String>();
if (digits.isEmpty()) {
return result;
}
result.add("");
for (int i = 0; i < digits.length(); i++) {
int index = Character.getNumericValue(digits.charAt(i));
String num = maps[index];
while (result.peek().length() == i) {
String pre = result.removeFirst();
for (Character character : num.toCharArray()) {
result.add(pre + character);
}
}
} return result;
}

[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. Java [leetcode 17]Letter Combinations of a Phone Number

    题目描述: 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/ 二.题目大意: 给定一段数字字符串,其中每个数 ...

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

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

随机推荐

  1. 关于@property()的那些属性及ARC简介

    @property()常用的属性有:nonatomic,atomic,assign,retain,strong,weak,copy. 其中atomic和nonatomic用来决定编译器生成的gette ...

  2. 【Python】 sorted函数

    我们需要对List.Dict进行排序,Python提供了两个方法对给定的List L进行排序,方法1.用List的成员函数sort进行排序,在本地进行排序,不返回副本方法2.用built-in函数so ...

  3. 第五百八十六天至第六百零五天 how ccan I 坚持

    考研中,勿扰... 我是个逗比,哈哈. 时间不够用了呢,哎.

  4. easyui datagrid 跨页选择

    $.fn.extend( memberList ,{ quickSearch : function() { var time1 = new Date(); /* this.datagrid.datag ...

  5. TJI读书笔记13-内部类

    TJI读书笔记13-内部类 TJI读书笔记13-内部类 创建内部类 内部类和外部类的关系 .this和.new 内部类和向上转型 局部内部类 匿名内部类 匿名内部类的定义和初始化 使用匿名内部类来实现 ...

  6. WPF的图片操作效果(一):RenderTransform

    一.RenderTransform类的成员: 1.TranslateTransform 平移效果 2.RotateTransform 旋转效果 3.ScaleTransform       缩放效果 ...

  7. codevs1230 元素查找

    1230 元素查找  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 钻石 Diamond 题解       题目描述 Description 给出n个正整数,然后有m个询问,每 ...

  8. spi_flash

    http://blog.chinaunix.net/uid-27406766-id-3384699.html

  9. Delphi 7学习开发控件

    我们知道使用Delphi快速开发,很大的一方面就是其强大的VCL控件,另外丰富的第三方控件也使得Delphi程序员更加快速的开发出所需要的程序.在此不特别介绍一些概念,只记录自己学习开发控件的步骤.假 ...

  10. java去中文

    java 去中文 package a.b; public class TrimCNTool { public static boolean checkCNChar(char oneChar) { if ...