博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Letter Combinations of a Phone Number
阅读量:4074 次
发布时间:2019-05-25

本文共 1545 字,大约阅读时间需要 5 分钟。

Letter Combinations of a Phone Number

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.

Java代码:

public class Solution {          Map
> map; public List
letterCombinations(String digits) { map = new HashMap
>(); this.map.put(2,new ArrayList
(Arrays.asList("a","b","c"))); this.map.put(3,new ArrayList
(Arrays.asList("d","e","f"))); this.map.put(4,new ArrayList
(Arrays.asList("g","h","i"))); this.map.put(5,new ArrayList
(Arrays.asList("j","k","l"))); this.map.put(6,new ArrayList
(Arrays.asList("m","n","o"))); this.map.put(7,new ArrayList
(Arrays.asList("p","q","r","s"))); this.map.put(8,new ArrayList
(Arrays.asList("t","u","v"))); this.map.put(9,new ArrayList
(Arrays.asList("w","x","y","z"))); return comb(digits); } public List
comb(String digits) { List
result = new LinkedList
(); if(digits.length() == 0) { result.add(new String("")); } else if(digits.length() == 1) { List
ret = new LinkedList
(); for(String c:map.get(Integer.parseInt(digits))) ret.add(c); return ret; } else { for(String s : comb(digits.substring(1))) { for(String c:map.get(Integer.parseInt(digits.substring(0,1)))) result.add(c + s); } } return result; } }
 

转载地址:http://xnuni.baihongyu.com/

你可能感兴趣的文章
mysql 跨机器查询,使用dblink
查看>>
mysql5.6.34 升级到mysql5.7.32
查看>>
dba 常用查询
查看>>
Oracle 异机恢复
查看>>
Oracle 12C DG 搭建(RAC-RAC/RAC-单机)
查看>>
Truncate 表之恢复
查看>>
Oracle DG failover 后恢复
查看>>
为什么很多程序员都选择跳槽?
查看>>
mongdb介绍
查看>>
Yotta企业云盘助力科技行业创高峰
查看>>
Yotta企业云盘更好地为教育行业服务
查看>>
Yotta企业云盘怎么帮助到能源化工行业
查看>>
企业云盘如何助力商业新发展
查看>>
医疗行业运用企业云盘可以带来什么样的提升
查看>>
媒体广告业如何运用云盘提升效率
查看>>
IOS开发的开源库
查看>>
Jenkins - sonarqube 代码审查
查看>>
Jenkins + Docker + SpringCloud 微服务持续集成(一)
查看>>
Jenkins + Docker + SpringCloud 微服务持续集成 - 单机部署(二)
查看>>
Jenkins + Docker + SpringCloud 微服务持续集成 - 高可用集群部署(三)
查看>>