[leetcode] 17. Letter Combinations of a Phone Number (medium)
递归DFS
class Solution {
Map<Character, String> mapping = new HashMap<>();
public List<String> letterCombinations(String digits) {
List<String> res = new ArrayList<>();
if (digits.isEmpty())
return res;
mapping.put('2', "abc");
mapping.put('3', "def");
mapping.put('4', "ghi");
mapping.put('5', "jkl");
mapping.put('6', "mno");
mapping.put('7', "pqrs");
mapping.put('8', "tuv");
mapping.put('9', "wxyz");
char[] cdigits=digits.toCharArray();
helper(cdigits, "", res);
return res;
}
void helper(char[] cdigits, String curStr, List<String> res) {
if (curStr.length() == cdigits.length) {
res.add(curStr);
return;
}
String curLetters = mapping.get(cdigits[curStr.length()]);
for (char c : curLetters.toCharArray()) {
helper(cdigits, curStr+c, res);
}
}
}
[leetcode] 17. Letter Combinations of a Phone Number (medium)的更多相关文章
- 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 ...
- [leetcode 17]Letter Combinations of a Phone Number
1 题目: Given a digit string, return all possible letter combinations that the number could represent. ...
- 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/ 二.题目大意: 给定一段数字字符串,其中每个数 ...
随机推荐
- kafka笔记2
Kafka是使用java开发的程序,所以它可以运行在多种操作系统上,安装Kafka之前,需要先安装Java环境,再安装zookeeper broker常规配置 1.broker.id 每个broker ...
- spring boot之actuator简介
当我们的开发工作进入尾声,部署上线之后,对于一个程序而言,可能才刚刚开始,对程序的运行情况的监控要伴随着整个生命周期. 如果这个工作由程序员自己来开发,也未尝不可,但本着不重复制造轮子的思想,我们尽量 ...
- 共识协议——RAFT&PBFT
区块链是一个没有中央权威的分布式对等系统.虽然权力下放可以防止各方的腐败行为,但是它必需要有一个可靠的共识协议来作出决策,让分散在世界各地的节点可以形成一致的意见.常见的共识算法有比特币采用的POW, ...
- 深入理解 Kafka 副本机制
一.Kafka集群 二.副本机制 2.1 分区和副本 2.2 ISR机制 2.3 不完全的首领选举 2.4 最少同步副本 ...
- tkinter + cefpython 仿美团桌面程序
使用js开发桌面程序目前是一个趋势,Electron是其中一个佼佼者,网上也不乏很多文章.今天主要是来讲一下cefpython. 用python的朋友,特别使用过tkinter开发过界面的,一定会觉得 ...
- spring 5.x 系列第11篇 —— 整合memcached (xml配置方式)
文章目录 一.说明 1.1 XMemcached客户端说明 1.2 项目结构说明 1.3 依赖说明 二.spring 整合 memcached 2.1 单机配置 2.2 集群配置 2.3 存储基本类型 ...
- Java基础篇01
01. 面向对象 --> 什么是面向对象 面向对象 面向对象程序设计,简称OOP(Object Oriented Programming). 对象: 指人们要研究的任何事物,不管是物理上具体的事 ...
- Ruby中的数值
数值类型 Ruby中所有数值都是Numeric类的子类对象,数值都是不可变对象. 数值类型的继承关系如下: Integer是整数,Float是浮点数类型,Rational是分数. 对于整数,要么是Fi ...
- (数据科学学习手札65)利用Python实现Shp格式向GeoJSON的转换
一.简介 Shp格式是GIS中非常重要的数据格式,主要在Arcgis中使用,但在进行很多基于网页的空间数据可视化时,通常只接受GeoJSON格式的数据,众所周知JSON(JavaScript Obje ...
- vboxnetctl: no such file or directory
 sudo /Library/StartupItems/VirtualBox/VirtualBox restart sudo /Library/StartupItems/VirtualBox/Vir ...