递归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. idea 导入maven项目

    1.import project 2.选择maven项目 3.选择第二个external moudle,选择maven, 4.点击next,一次点击1,2,3,4 5.设置maven环境 6.点击ok ...

  2. 修改zookeeper jvm参数

    在zkServer.sh中,增加以下参数: start)    echo  -n "Starting zookeeper ... "    if [ -f $ZOOPIDFILE ...

  3. tortoisegit密码找回之抓包法

    因为一直用tortoisegit记住密码(此方法只适用于tortoisegit有记住密码),昨天需要登陆gitlab发现密码忘记了,用了N个常用默认密码都不对:和度娘交流一会儿也无果,gitlab里的 ...

  4. vuejs切换导航条高亮路由高亮做法

    我的GitHub前端经验总结,喜欢的话请点star✨✨Thanks.:https://github.com/liangfengbo/frontend-develop vuejs导航条高亮我的做法: 用 ...

  5. WebFlux 集成 Thymeleaf 、 Mongodb 实践 - Spring Boot(六)

    这是泥瓦匠的第105篇原创 文章工程: JDK 1.8 Maven 3.5.2 Spring Boot 2.1.3.RELEASE 工程名:springboot-webflux-5-thymeleaf ...

  6. vi的替换使用、如何让linux有回收站功能、系统重要文件、目录数据

      1 vi的替换使用方法 vi使用的原理 (编辑文件会生成一个隐藏临时文件) 1.1 替换文件内容方法:vi (1)%s#oldboy#oldgirl#g --- 将oldboy全部替换为oldgi ...

  7. 【工具】读取proprtties工具类

    获取properties内容: 基本的使用看网络上大多是这样的,使用时注意线程安全以及读写的实时性问题. 1.直接通过流读取(反射): InputStream inStream =  this.get ...

  8. php __autoload 在有命名空间的时候失效(使用的局限性)

    如果要使用__autoload方法,则不能再之前使用namespace,    使用命名空间,则至少php5.3不再调用__autoload方法    因此如果需要使用__autoload和命名空间, ...

  9. Solr 18 - 通过SolrJ局部更新Solr中的文档 (原子操作、非覆盖操作)

    目录 1 需求分析 2 需求实现 2.1 pom.xml依赖 2.2 Java代码示例 3 补充说明 3.1 关于文档中_version_的取值说明 3.2 store=true/false的区别 1 ...

  10. 从零开始实现ASP.NET Core MVC的插件式开发(一) - 使用ApplicationPart动态加载控制器和视图

    标题:从零开始实现ASP.NET Core MVC的插件式开发(一) - 使用Application Part动态加载控制器和视图 作者:Lamond Lu 地址:http://www.cnblogs ...