[leetcode 17]Letter Combinations of a Phone Number
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的更多相关文章
- 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 ...
- [LeetCode] 17. Letter Combinations of a Phone Number 电话号码的字母组合
Given a string containing digits from 2-9inclusive, return all possible letter combinations that the ...
- Java [leetcode 17]Letter Combinations of a Phone Number
题目描述: Given a digit string, return all possible letter combinations that the number could represent. ...
- Leetcode 17.——Letter Combinations of a Phone Number
Given a digit string, return all possible letter combinations that the number could represent. A map ...
- [leetcode]17. Letter Combinations of a Phone Number手机键盘的字母组合
Given a string containing digits from 2-9 inclusive, return all possible letter combinations that th ...
- [LeetCode] 17. Letter Combinations of a Phone Number ☆☆
Given a digit string, return all possible letter combinations that the number could represent. A map ...
- [LeetCode]17. Letter Combinations of a Phone Number电话号码的字母组合
Given a string containing digits from 2-9 inclusive, return all possible letter combinations that th ...
- LeetCode——17. Letter Combinations of a Phone Number
一.题目链接: https://leetcode.com/problems/letter-combinations-of-a-phone-number/ 二.题目大意: 给定一段数字字符串,其中每个数 ...
- LeetCode 17 Letter Combinations of a Phone Number (电话号码字符组合)
题目链接 https://leetcode.com/problems/letter-combinations-of-a-phone-number/?tab=Description HashMap< ...
随机推荐
- Web程序设计笔记-第一章:基础知识
1,Web服务器 (1)Web服务器操作 Web浏览器通过向服务器发送URL来与Web服务器进行通信.URL可以指定两种不同资源中的一种:某个文件或者某个程序. Web客户机和Web服务器之间所有的通 ...
- Changing SharePoint Default port ( 80 ) to another port ( 79 ).
Introduction In this How-To I will change my port from 80 to 79, probably because I want to host s ...
- python 排序
python 写的排序,实现起来还是比较简单 #快速排序 def qsort(L): if len(L)>1: return qsort([i for i in L[1:] if i<L[ ...
- DDK Build的DIRS和SOURCE文件
DDK Build编译的时候,使用3个文件来描述被编译的源码,其中SOURCES和Makefile是必须的,而DIRS则只在划分目录的时候有用.Makefile在这里作用并不大但是必须和SOURCES ...
- asp.net GDI+绘制矩形渐变
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.We ...
- VS2010英文版修改删除、注释快捷键
VS2010英文版修改删除.注释快捷键 打开快捷键修改面板,然后修改
- ORA-12505 错误解决
在Fedora下安装了Oracle 10gR2,安装完成之后,使用netca创建了监听,创建的时候没有使用默认的LISTENER和1521端口,而是使用了LISTENER_DELL和1522端口,终 ...
- 也说面试 - 一个努力的iOS Dev
你们在金色的余晖中回家,而我却在银色的温柔中,匆匆潜行-----这是我的现状. 今年的招工形式不是很好,难找工作:也难招人.写这篇博客,是为了给各位在找工作的iOS dev 一些参考. 上篇:换坑(去 ...
- Codeforces Round #383 _python作死系列
A. Arpa's hard exam and Mehrdad's naive cheat 题意求1378的n次方的最后一位,懒的写循环节 瞎快速幂 py3 int和LL 合并为int了 def q_ ...
- 第三十八章 springboot+docker(maven)
回顾上一章的整个部署过程: 使用"mvn install"进行打包jar 将jar移动到与Dockerfile文件相同的文件夹下 编写Dockerfile文件 使用"do ...