[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< ...
随机推荐
- jquery tmpl遍历
最近发现大家用模板渲染一些顺带逻辑功能代码块时,用jquery tmpl较多,遇到了一些问题,现在就个人以前研究过的一切常用功能作介绍,主要针对遍历,其它的大家可以自行浏览一起网站,如:http:// ...
- js实现判断浏览器版本
//判断浏览器版本是否过低 var ua = navigator.userAgent.toLowerCase(); if (window.ActiveXObject) var IEversion = ...
- 关于Nios II的启动分析(转载)
原文地址:http://hi.baidu.com/goatdai/item/cc33671545d89243e75e06ad 常用到的存储器包括SDRMA.SRAM.FLASH.Onchip_memo ...
- 深入理解js——一切都是对象
"一切皆对象" 当然也不是所有的都是对象,值类型(undefined,number,string,boolean)就不是对象:而函数.对象.数组.null.new Number(1 ...
- ios 学习总结之动画(转)
转自:http://blog.sina.com.cn/s/blog_a85effc301012wu4.html UIView的,翻转.旋转,偏移,翻页,缩放,取反的动画效果 翻转的动画 //开始动 ...
- java基础八 [序列化和文件的输入/输出](阅读Head First Java记录)
对象具有状态和行为两种属性.行为存在类中的方法中,想要保存状态有多种方法,这里介绍两种: 一是保存整个当前对象本身(通过序列化):一是将对象中各个状态值保存到文件中(这种方式可以给其他非JAVA程序用 ...
- 关于生物信息学与R的相关资料和网站
生物信息学的相关论坛:http://www.omicshare.com/forum/ 糗世界:http://qiubio.com:8080/ 统计之都网站 绘制QQ图和曼哈顿图:http://www. ...
- laravel 表单验证
$this->validate($request, [ 'sn' =>['regex:/^\d{6}$/','required'], 'user' => ['numeric','mi ...
- URL验证
function isURL(str_url) { var strRegex = "^((https|http|ftp|rtsp|mms)?://)" + "?(([0- ...
- PHPMyadmin 配置文件详解(配置)
PHPMyadmin配置文件config.inc.php内容如下,在需要设置的地方增加了相关注释. 非常适合对数据库操作命令不熟悉的数据库管理者,下面我就说下怎么安装该工具: 1.先到网上下载phpm ...