[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/ 二.题目大意: 给定一段数字字符串,其中每个数 ...
随机推荐
- Delphi 7.0常用函数速查手册(磁盘文件类)
在Delphi 7.0中,已为我们定义好了非常多的函数,大致分类有6种:数据类型转换函数.字符串.数组操作函数.文件.磁盘操作函数.内存.指针操作函数.数学运算函数.日期函数. 在Delphi中调用函 ...
- Delphi 7下IGDIPlus库的使用
IGDI+是一个免费开源封装微软GDI+功能的Delphi库,该库使得可以用Delphi语言代码快速简短的实现复杂GDI+应用程序.官方网站:http://www.mitov.com/html/igd ...
- 什么是Android NDK
1.NDK是一系列工具的集合. NDK提供了一系列的工具,帮助开发者快速开发C(或C++)的动态库,并能自动将so和java应用一起打包成apk.这些工具对开发者的帮助是巨大的. NDK集成了交叉编译 ...
- 如何在 Xcode 中进行 Qt 开发(可使用使用 Homebrew 来安装qt)
第一步 安装 Qt 分为两种情况: 1. 希望使用 Qt Quick 等先进Qt5技术, 2. 只需要 Qt 4.8的类库即可. 第一种, 直接去官网下载 Mac安装包, 在此不作过多说明, 开发时也 ...
- 设置Windows服务的访问权限
作者:beyond 默认情况下,只有管理员组成员.LocalSystem和Power Users组成员帐户才有权启动.停止服务.为了让普通用户也可以控制该服务,我们可以手动设置其访问权限.可能有些初学 ...
- c++用参数返回堆上的空间
<高质量c++和c编程>7.4 指针参数是如何传递内存的一节中写道 void GetMemory(char *p, int num) { p = (char *)malloc(sizeof ...
- 使用spring容器干掉if-else
spring容器干掉if-else 场景说明 最近新做一个项目,需要对不同店铺的商品做不同处理.例如storeA需要进行handleA操作,storeB需要进行handleB操作,如此类推 大家很容易 ...
- 玩转java多线程(wait和notifyAll的正确使用姿势)
转载请标明博客的地址 本人博客和github账号,如果对你有帮助请在本人github项目AioSocket上点个star,激励作者对社区贡献 个人博客:https://www.cnblogs.com/ ...
- 【commons-lang3工具】JAVA脱敏工具
前言:commons-langbao中有很多方便的工具,无需我们自己去实现,能够节省很多开发时的问题: 1.工具包,引入依赖,jDK8对应的版本如下: <!-- https://mvnrepos ...
- Jenkins+Python+GitLab持续集成
创建任务 登录Jenkins,点击左侧列表的新建选项.输入任务名称,选择构建一个自由风格的软件项目,点击确定. 配置 在任务配置界面,可以设置General标签中的丢弃旧的构建选项,设置保持构建的天数 ...