给一个数字字符串,每个数字代表一个字母,请返回其所有可能的字母组合。

下图的手机按键图,就表示了每个数字可以代表的字母。

您在真实的面试中是否遇到过这个题?

Yes
样例

给定 "23"

返回 ["ad", "ae", "af", "bd", "be", "bf", "cd", "ce", "cf"]

class Solution {
public:vector<string> letterCombinations(string& digits) {vector<string> res;if(digits.empty()) return res;vector<string>dic(10);dic[0]=" ";dic[1]="1";dic[2]="abc";dic[3]="def";dic[4]="ghi";dic[5]="jkl";dic[6]="mno";dic[7]="pqrs";dic[8]="tuv";dic[9]="wxyz";return helper(digits,0,dic);}vector<string> helper(string& digits,int begin,vector<string>&dic){vector<string>res;if(digits.empty()) return vector<string>();if(begin==digits.size()) return vector<string>();int digit=digits[begin]-'0';string tmp=dic[digit];int n=tmp.size();for(int i=0;i<n;i++){string ttmp;ttmp.push_back(tmp[i]);vector<string>next=helper(digits,begin+1,dic);int m=next.size();if(m==0){res.push_back(ttmp);}else{for(int j=0;j<m;j++){res.push_back(ttmp+next[j]);}}}return res;}
};

letter-combinations-of-a-phone-number相关推荐

  1. Leetcode 17 - Letter Combinations of a Phone Number

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

  2. LeetCode Letter Combinations of a Phone Number

    LeetCode解题之Letter Combinations of a Phone Number 原题 手机按键上每一个数字都相应了多个字母,如2相应了"abc",现给出一个数字串 ...

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

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

  4. [ 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 ...

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

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

  6. leetCode:Letter Combinations of a Phone Number

    题目 Letter Combinations of a Phone Number Given a digit string, return all possible letter combinatio ...

  7. Leetcode #17 Letter Combinations of a Phone Number Z9键盘字母组合解题小节

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

  8. [Swift]LeetCode17. 电话号码的字母组合 | Letter Combinations of a Phone Number

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★ ➤微信公众号:山青咏芝(shanqingyongzhi) ➤博客园地址:山青咏芝(https://www.cnblog ...

  9. Letter Combinations of a Phone Number

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

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

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

最新文章

  1. linux的网络地址配置,教你如何完成Linux网络地址配置
  2. 【原创】多台电脑如何公用一个键盘鼠标进行操作 - Mouse with Borders 软件
  3. k8s kafka集群 连接不上_图解 K8s 核心概念和术语
  4. math.hypot java_Java math
  5. ASP.Net服务性能优化原则
  6. Http 四种请求访问代码 HttpGet HttpPost HttpPut HttpDelete .
  7. 越狱Season 1-Episode 15: By the Skin and the Teeth
  8. 黑客恶意修改化学成分参数,远程投毒饮用水
  9. Charles使用教程
  10. ModelAndView详解
  11. JVM上篇学习3--内存与垃圾回收
  12. 分布式集群中网络分区问题
  13. Proteus常用元件对照表(最全)
  14. 表贴电阻尺寸与什么有关_贴片电阻、贴片电容规格、封装、尺寸、功率(转)
  15. Elasticsearch 拼音分词器
  16. Android之权限(permission)大全
  17. dnf第七章waiguaⅢ∨dnf第七章好感度【=dnf第七章免费外挂
  18. Java-给会员打折
  19. Android Path之Direction.CW、Direction.CCW
  20. 最近搞的AGV调度控制中心

热门文章

  1. 计算机629错误代码,宽带连接时提示错误629是什么原因?
  2. eslint-disable的使用
  3. 2020互联网公司端午礼盒大比拼!
  4. 经典算法21--十字链表
  5. Xen和香蕉派的故事
  6. Thinkpad E14 Win10上安装Ubuntu双系统安装
  7. 斗罗大陆 暗夜精灵(下)
  8. 3月27日——4月2日:新闻采访写作
  9. python中callable_Python callable() 函数
  10. 西部世界IPFS矿业,牛熊穿越的可能性