017 Letter Combinations of a Phone Number 电话号码的字母组合
给定一个数字字符串,返回数字所有可能表示的字母组合。
输入:数字字符串 "23"
输出:["ad", "ae", "af", "bd", "be", "bf", "cd", "ce", "cf"].
详见:https://leetcode.com/problems/letter-combinations-of-a-phone-number/description/
实现语言:Java
class Solution {
public List<String> letterCombinations(String digits) {
List<String> result =new ArrayList<>();
if(digits == null || digits.isEmpty()){
return result;
}
result.add("");
String []btns = {"", "", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
for(int i =0 ; i < digits.length() ;i++){
List<String> tmp = new ArrayList<>();
String letter = btns[digits.charAt(i)-'0'];
//遍历上一个列表,取出每一个元素,并和新的元素的每一个字符加起来保存
for(int j = 0 ; j < result.size();j++){
//遍历当前数字对应的所有字符
for(int k = 0; k< letter.length(); k++){
tmp.add(result.get(j)+letter.charAt(k));
}
}
result = tmp;
}
return result;
}
}
参考:https://vvaaiinn.iteye.com/blog/2208353
https://www.cnblogs.com/kepuCS/p/5271654.html
017 Letter Combinations of a Phone Number 电话号码的字母组合的更多相关文章
- [LintCode] Letter Combinations of a Phone Number 电话号码的字母组合
Given a digit string, return all possible letter combinations that the number could represent. A map ...
- [LeetCode] 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-9inclusive, return all possible letter combinations that the ...
- 【LeetCode】17. Letter Combinations of a Phone Number 电话号码的字母组合
作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 个人公众号:负雪明烛 本文关键词:电话号码, 字母组合,回溯法,题解,leetcode, ...
- lintcode 中等题:Letter Combinations of a Phone Number 电话号码的字母组合
题目 电话号码的字母组合 给一个数字字符串,每个数字代表一个字母,请返回其所有可能的字母组合. 下图的手机按键图,就表示了每个数字可以代表的字母. 样例 给定 "23" 返回 [& ...
- [LeetCode]17. Letter Combinations of a Phone Number电话号码的字母组合
Given a string containing digits from 2-9 inclusive, return all possible letter combinations that th ...
- Leetcode17.Letter Combinations of a Phone Number电话号码的字母组合
给定一个仅包含数字 2-9 的字符串,返回所有它能表示的字母组合. 给出数字到字母的映射如下(与电话按键相同).注意 1 不对应任何字母. 示例: 输入:"23" 输出:[&quo ...
- 【JAVA、C++】LeetCode 017 Letter Combinations of a Phone Number
Given a digit string, return all possible letter combinations that the number could represent. A map ...
- 【LeetCode】017. Letter Combinations of a Phone Number
题目: Given a digit string, return all possible letter combinations that the number could represent. A ...
随机推荐
- FPGA, Float 32bit, multiplyier by Verilog
1, FPGA device, using three 18bit x 18 bit multiplier to implement 32bit float multiplier 2, compari ...
- orcal数据库得连接必须用localhost,url中不要用127.0.0.1,不然无法连接
orcal数据库得连接必须用localhost,url中不要用127.0.0.1,不然无法连接,
- Python:os.walk()和os.path.walk()用法
转于:https://www.cnblogs.com/zmlctt/p/4222621.html 博主:zmlctt 一.os.walk() 函数声明:os.walk(top,topdown=True ...
- rails中一个窗体多个模型——fields_for
详细参考 http://railscasts.com/episodes/73-complex-forms-part-1中part-1.2.3部分 借助field_for可以生成表单来处理两个或更多模型 ...
- ES6学习之函数扩展
函数默认参数 function test(x = 1, y = 2) { return x + y } test(5, 6) test() 若默认参数在必须参数之前,要想取得默认参数,只有当传入的值为 ...
- linux命令-tar打包和压缩并用
tar在打包的时候进行压缩 支持 gzip bzip2 xz 格式 -z gzip格式 -j bzip2格式 -J xz格式 压缩打包 [root@wangshaojun ~]# tar -zc ...
- AngularJs(Part 8)--Filters
Filters AngularJS provides fileters to transfrom data from one kind to another . For example: {{ ...
- hdu1077
#include<iostream> #include<cmath> using namespace std; struct Point { double x,y; }; do ...
- C#----接口的显式实现
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace 接口 { ...
- php用百度地图API进行逆地址解析
<?php /** * 根据地理坐标获取国家.省份.城市,及周边数据类(利用百度Geocoding API实现) * 百度密钥获取方法:http://lbsyun.baidu.com/apico ...