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. C#占位符和格式化字符串

    static void Main() { string c=Console.ReadLine(); string d=Console.ReadLine(); Console.WriteLine(c+& ...

  2. hdu 2196 computer

    Computer Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Su ...

  3. 特征工程 dataframe格式

    import os import copy import codecs import operator import re from math import log from pyspark.sql ...

  4. How to Shorten the Paper

    . Remember: you are writing for an expert. Cross out all that is trivial or routine. . Avoid repetit ...

  5. Android菜鸟成长记5-ADB和sqllite

    Android开发环境中,ADB是我们进行Android开发经常要用的调试工具,它的使用当然是我们Android开发者必须要掌握的. ADB概述 Android Debug Bridge,Androi ...

  6. Ubuntu12.04-x64编译Hadoop2.2.0和安装Hadoop2.2.0集群

      本文Blog地址:http://www.cnblogs.com/fesh/p/3766656.html   本文对Hadoop-2.2.0源码进行重新编译(64位操作系统下不重新编译会有版本问题) ...

  7. [转载] 4. JebAPI 之 jeb.api.ui

    本文转载自: https://www.zybuluo.com/oro-oro/note/145250 JebInstance可以通过getUI()方法来获得jeb.api.ui.JebUI. JebU ...

  8. Java NIO教程 Channel

    Channel是一个连接到数据源的通道.程序不能直接用Channel中的数据,必须让Channel与BtyeBuffer交互数据,才能使用Buffer中的数据. 我们用FileChannel作为引子, ...

  9. machine learning----->学习成绩

    斯坦福大学机器学习公开课学习成绩:

  10. poj 2584 T-Shirt Gumbo (二分匹配)

    T-Shirt Gumbo Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 2571   Accepted: 1202 Des ...