递归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)的更多相关文章

  1. 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 ...

  2. [LeetCode] 17. Letter Combinations of a Phone Number 电话号码的字母组合

    Given a string containing digits from 2-9inclusive, return all possible letter combinations that the ...

  3. [leetcode 17]Letter Combinations of a Phone Number

    1 题目: Given a digit string, return all possible letter combinations that the number could represent. ...

  4. Java [leetcode 17]Letter Combinations of a Phone Number

    题目描述: Given a digit string, return all possible letter combinations that the number could represent. ...

  5. Leetcode 17.——Letter Combinations of a Phone Number

    Given a digit string, return all possible letter combinations that the number could represent. A map ...

  6. [leetcode]17. Letter Combinations of a Phone Number手机键盘的字母组合

    Given a string containing digits from 2-9 inclusive, return all possible letter combinations that th ...

  7. [LeetCode] 17. Letter Combinations of a Phone Number ☆☆

    Given a digit string, return all possible letter combinations that the number could represent. A map ...

  8. [LeetCode]17. Letter Combinations of a Phone Number电话号码的字母组合

    Given a string containing digits from 2-9 inclusive, return all possible letter combinations that th ...

  9. LeetCode——17. Letter Combinations of a Phone Number

    一.题目链接: https://leetcode.com/problems/letter-combinations-of-a-phone-number/ 二.题目大意: 给定一段数字字符串,其中每个数 ...

随机推荐

  1. Qt DLL总结【三】-VS2008+Qt 使用QPluginLoader访问DLL

    目录 Qt DLL总结[一]-链接库预备知识 Qt DLL总结[二]-创建及调用QT的 DLL Qt DLL总结[三]-VS2008+Qt 使用QPluginLoader访问DLL 开发环境:VS20 ...

  2. C++ 王者归来:对编程语言的需求总结为四个:效率,灵活,抽象,生产率(C++玩的是前三个,Java和C#玩的是后两个)

    Why C++ ? 王者归来(转载) 因为又有人邀请我去Quora的C2C网站去回答问题去了,这回是 关于 @laiyonghao 的这篇有点争议的博文<2012 不宜进入的三个技术点>A ...

  3. Codility---CountFactors

    Task description A positive integer D is a factor of a positive integer N if there exists an integer ...

  4. sql 日志恢复

    可能有不少朋友遇到过这样的问题: update或delete语句忘带了where子句,或where子句精度不够,执行之后造成了严重的后果,这种情况的数据恢复只能利用事务日志的备份来进行,所以如果你的S ...

  5. arcgis api for js 4.X 出现跨域问题

    arcgis api for js 4.X 出现跨域问题 XMLHttpRequest cannot load http://localhost/4.3/4.3/esri/workers/mutabl ...

  6. spring boot热部署devtools

    1 pom.xml文件 注:热部署功能spring-boot-1.3开始有的 <!--添加依赖--> <dependency> <groupId>org.sprin ...

  7. 05-MySQL的完整性约束

    1.整体说明(1)讨论重点内容    not null 与default    unique:表中该值唯一,不能有重复值    primary    auto_increment    foreign ...

  8. 深入解析Hyperledger Fabric启动的全过程

    在这篇文章中,使用fabric-samples/first-network中的文件进行fabric网络(solo类型的网络)启动全过程的解析.如有错误欢迎批评指正. 至于Fabric网络的搭建这里不再 ...

  9. Storm —— 单机环境搭建

    1. 安装环境要求 you need to install Storm's dependencies on Nimbus and the worker machines. These are: Jav ...

  10. SpringBoot 缓存注解 与EhCache的使用

    在SpringBoot工程中配置EhCache缓存 1.在src/main/resources下新建ehcache.xml文件 eternal=true //缓存永久有效,false相反 maxEle ...