1 题目理解

此道题目基于我们前几年用的,或许还有这几年用的九宫格输入法。九宫格上的每个数字对应着不同的字母,现在说,如果给定你一个数字,问你可以对应到多少种的字母组合?

这道题的解题方式,就是直接递归搜索就好,尝试每种可能。

这道题我觉得考点在于自己程序的书写,如何有效率的保存和组合这些可能的字符。

2 原题

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”].

3 AC解

public class Solution {
//我用来加快检索速度的方式,形成字典final static char[][] map = new char[][]{{},{},{'a','b','c'},{'d','e','f'},{'g','h','i'},{'j','k','l'},{'m','n','o'},{'p','q','r','s'},{'t','u','v'},{'w','x','y','z'}};  List<String> result;char[] chars;public void dfs(String tmp,int index){if(index==chars.length){result.add(tmp);return ;}else{for(int j=0;j<map[chars[index]].length;j++){dfs(tmp+map[chars[index]][j],index+1);}}}public List<String> letterCombinations(String digits) {result=new ArrayList<String>();chars=digits.toCharArray();if(chars.length==0)return result;for(int j=0;j<chars.length;j++){chars[j]-='0';}dfs("",0);return result;}
}

Leetcode #17 Letter Combinations of a Phone Number Z9键盘字母组合解题小节相关推荐

  1. 【DFS】LeetCode 17. Letter Combinations of a Phone Number

    LeetCode 17. Letter Combinations of a Phone Number Solution1:我的答案 利用8皇后同样的方法,回溯+递归 时间复杂度O(3n)O(3n)O( ...

  2. LeetCode | 0017. Letter Combinations of a Phone Number电话号码的字母组合【Python】

    LeetCode 0017. Letter Combinations of a Phone Number电话号码的字母组合[Medium][Python][回溯][DFS][暴力] Problem L ...

  3. [ LeetCode ] #17. Letter Combinations of a Phone Number(电话按键组合字符 C++ Python)

    题目:17. Letter Combinations of a Phone Number Difficulty: Medium Given a string containing digits fro ...

  4. Leetcode 17 - Letter Combinations of a Phone Number

    题目 https://leetcode.com/problems/letter-combinations-of-a-phone-number/ 题意 已知在九宫格的输入法上,2对应的字符是a\b\c, ...

  5. [LeetCode] 17. Letter Combinations of a Phone Number

    题目内容 给定一个仅包含数字 2-9 的字符串,返回所有它能表示的字母组合. 给出数字到字母的映射如下(与电话按键相同).注意 1 不对应任何字母. https://leetcode-cn.com/p ...

  6. LeetCode 17. Letter Combinations of a Phone Number

    题意:给出数字串,输出对应的字母串组合,数字与字母的对应关系为手机上的 思路:使用递归,使用字符数组来存储递归选取时的字母,当到达数字串长度时,将字符数组转换为字符串 注意:数字串为空串时,输出为空 ...

  7. Leetcode 17. Letter Combinations of a Phone Number(python)

    笨方法回溯啦 class Solution(object):def letterCombinations(self, digits):""":type digits: s ...

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

    给定一个仅包含数字 2-9 的字符串,返回所有它能表示的字母组合. 给出数字到字母的映射如下(与电话按键相同).注意 1 不对应任何字母. 示例: 输入:"23" 输出:[&quo ...

  9. LeetCode 17. Letter Combinations of a Phone Number--笔试题--C++,Python解法

    题目地址:Letter Combinations of a Phone Number - LeetCode Given a string containing digits from 2-9 incl ...

最新文章

  1. Python搭建Keras CNN模型破解网站验证码
  2. 数据结构与算法笔记(七)—— 选择排序
  3. hls.js播放hls直播源
  4. nginx php mysql 部署_Linux+Nginx+Mysql+Php运维部署
  5. android 生命周期_Android生命周期组件 Lifecycle 源码详解(一)
  6. [渝粤教育] 广东-国家-开放大学 21秋期末考试财务管理10164k2 (3)
  7. 电动葫芦使用注意事项(转载)
  8. 智伴机器人广西团队_畅想科技 智绘未来——2020年全区乡村学校少年宫科技体验日活动在广西科技馆举办...
  9. Vue报错Cannot find module ‘webpack-cli/bin/config-yargs‘
  10. 【王道考研计算机网络】—OSI参考模型
  11. 执行环境,作用域链,闭包
  12. vim 使用 Tricks
  13. WinRAR 永久去除弹窗广告
  14. 超好用的卸载工具——geek(免安装)
  15. BoundsChecker使用
  16. python周环比增长率_Python如何计算环比增长率
  17. 一个一本正经的科普--5G是什么?
  18. 安卓 新闻客户端毕业设计项目
  19. 做人最重要的是学会珍惜,爱情如此,人生又何尝不是呢?
  20. Java之国际化操作

热门文章

  1. hduoj 2000
  2. Realm数据库使用教程(一):Realm配置和Stetho配置
  3. FastDFS 的安装、使用、踩坑过程
  4. 单元测试(三)--立即测试模型与单一测试模型
  5. 主机名变为“bogon”的解决办法
  6. flash打造动漫中另一种侧面眨眼效果
  7. 用C语言实现strcpy函数和strncpy函数
  8. BAPI : 计划订单的创建,修改和删除批导问题
  9. Semaphore 源码解读
  10. OLAP阵营又增一猛将,比肩Power BI不是说说而已