题目描述:

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

Note:
Although the above answer is in lexicographical order, your answer could be in any order you want.

  

  这道题不算难,想想就出来了。

solution:

vector<string> letterCombinations(string digits) {int n = digits.size();vector<string> res;if(n == 0)return res;res.push_back("");string numap[] = {"#","#","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};for (int i = 0;i < n;++i){vector<string> tmp;for(int j = 0;j < res.size();++j)for(int k = 0;k < numap[digits[i]-'0'].size();++k)tmp.push_back(res[j] + numap[digits[i]-'0'][k]);res = tmp;}return res;
}

  此题还有其他解法,《编程之美》中也有相似题目,暂时先这样了。

转载于:https://www.cnblogs.com/gattaca/p/4315884.html

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. [LeetCode] 17. Letter Combinations of a Phone Number

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

最新文章

  1. Python培训分享:python如何用cookie实现自动模拟登录?
  2. python axis 0_axis=0在sum()和dropna()中的行为似乎不同
  3. 面试官:react和vue有什么区别吗?
  4. centos 7.6.1810 升3.7时 python和yum被误删除的恢复
  5. unique函数_Office 365函数新世界:动态数组
  6. SMO算法原理转载+自己补充
  7. MySql DATE_FORMAT函数用法
  8. 微软推出Visual Studio Kubernetes工具包预览版
  9. 两年了,你还是那个你 | 今日最佳
  10. 八中计算机是学啥的,北京八中:居然有这么好玩的课
  11. BrnShop开源网上商城第二讲:ASP.NET MVC框架
  12. 重装谷歌浏览器chrome:未知错误导致安装失败
  13. C函数形参列表与汇编寄存器的对应关系
  14. mysql deadlock6_mysql deadlock、Lock wait timeout解决和分析
  15. MySql(16)——Spring data jpa mysql 乐观锁 与 AtomicInteger
  16. ros之TF坐标转换
  17. linux日常学习笔记
  18. 电视盒子cpu天梯图 电视盒子CPU性能天梯图2022
  19. 发那科程序全部输出_如何拷贝FANUC系统全部程序
  20. SQLmap————10、sqlmap详细命令

热门文章

  1. 11 旋转数组的最小数字
  2. hibernate Day1 案例代码
  3. Flask 应用最佳实践
  4. ExtJS视频学习笔记
  5. 学习资料收集:计算机系统基础
  6. android Fragments (Android官方文档中文版)
  7. WebDevHelper -- RESTful服务和Ajax开发时的利器
  8. [冲啊!!!!!]小白SLAM相关基础知识
  9. mui获取css参数,Mui-获取时间-调用手机api
  10. java http请求头_http的请求头含义及如何用java发送