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. python迭代器与生成器

    1.迭代器 iterator 迭代器是一种对象类型!可以由生成器生成! 迭代器对象从集合的第一个元素开始访问,直到所有的元素被访问完结束.迭代器的一大优点是不要求事先准备好整个迭代过程中所有的元素.迭 ...

  2. js获取浏览器语言(ie、ff、chrome)、contextpath

    /js获取浏览器语言(ie.ff.chrome) var language_en_us = "en-us"; var language_zh_cn = "zh-cn&qu ...

  3. MFC的自定义消息的定义与使用

    自定义消息的响应和资源消息的响应有很多类似之处:资源消息的响应是以资源的ID号作为标识的:自定义的消息要自己声明消息ID. 一.           定义: 第一步要声明消息: #define WM_ ...

  4. 文件读写方法1.FileInputStream和FileOutputStream

    package fileTest; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundEx ...

  5. 炫酷的时钟--canvas初体验

    先啥也不说:来张效果图 我是根据:http://www.imooc.com/learn/133 这里的课程进行学习的.大大的感谢liuyubobobo老师的深入浅出的讲解!! 我在这里仅仅提供我自己的 ...

  6. 解析工具Goson

    /** * 解析申请分配座位席别 * @param json * @return */ public static TrainOrderResponse getTrainOrder(String js ...

  7. supervisor 配置

    1. 生成配置文件$ echo_supervisord_conf > /etc/supervisord.conf 2.修改配置文件vi /etc/supervisord.conf找到[inclu ...

  8. localstorage,sessionstorage使用

    今天看了一下HTML5,也算是简单的学习一下吧,HTML5 提供了两种在客户端存储数据的新方法:localstorage,sessionstorage. localStorage - 没有时间限制的数 ...

  9. INNO SETUP 5.5.0以上版本中文语言包

    ; *** Inno Setup version 5.5.0+ Chinese messages ***;; To download user-contributed translations of ...

  10. java 查询 mongodb 中的objectid

    网上找了很久查询objectid的方法都是错的,用mongovue能查询出来,但就是用java不知道怎么查询 1.mongovue里的查询方式: {"_id" : ObjectId ...