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"].
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相关推荐
- Leetcode 17 - Letter Combinations of a Phone Number
题目 https://leetcode.com/problems/letter-combinations-of-a-phone-number/ 题意 已知在九宫格的输入法上,2对应的字符是a\b\c, ...
- LeetCode Letter Combinations of a Phone Number
LeetCode解题之Letter Combinations of a Phone Number 原题 手机按键上每一个数字都相应了多个字母,如2相应了"abc",现给出一个数字串 ...
- 【DFS】LeetCode 17. Letter Combinations of a Phone Number
LeetCode 17. Letter Combinations of a Phone Number Solution1:我的答案 利用8皇后同样的方法,回溯+递归 时间复杂度O(3n)O(3n)O( ...
- [ 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 ...
- LeetCode | 0017. Letter Combinations of a Phone Number电话号码的字母组合【Python】
LeetCode 0017. Letter Combinations of a Phone Number电话号码的字母组合[Medium][Python][回溯][DFS][暴力] Problem L ...
- leetCode:Letter Combinations of a Phone Number
题目 Letter Combinations of a Phone Number Given a digit string, return all possible letter combinatio ...
- Leetcode #17 Letter Combinations of a Phone Number Z9键盘字母组合解题小节
1 题目理解 此道题目基于我们前几年用的,或许还有这几年用的九宫格输入法.九宫格上的每个数字对应着不同的字母,现在说,如果给定你一个数字,问你可以对应到多少种的字母组合? 这道题的解题方式,就是直接递 ...
- [Swift]LeetCode17. 电话号码的字母组合 | Letter Combinations of a Phone Number
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★ ➤微信公众号:山青咏芝(shanqingyongzhi) ➤博客园地址:山青咏芝(https://www.cnblog ...
- [LeetCode] 17. Letter Combinations of a Phone Number
题目内容 给定一个仅包含数字 2-9 的字符串,返回所有它能表示的字母组合. 给出数字到字母的映射如下(与电话按键相同).注意 1 不对应任何字母. https://leetcode-cn.com/p ...
最新文章
- Python培训分享:python如何用cookie实现自动模拟登录?
- python axis 0_axis=0在sum()和dropna()中的行为似乎不同
- 面试官:react和vue有什么区别吗?
- centos 7.6.1810 升3.7时 python和yum被误删除的恢复
- unique函数_Office 365函数新世界:动态数组
- SMO算法原理转载+自己补充
- MySql DATE_FORMAT函数用法
- 微软推出Visual Studio Kubernetes工具包预览版
- 两年了,你还是那个你 | 今日最佳
- 八中计算机是学啥的,北京八中:居然有这么好玩的课
- BrnShop开源网上商城第二讲:ASP.NET MVC框架
- 重装谷歌浏览器chrome:未知错误导致安装失败
- C函数形参列表与汇编寄存器的对应关系
- mysql deadlock6_mysql deadlock、Lock wait timeout解决和分析
- MySql(16)——Spring data jpa mysql 乐观锁 与 AtomicInteger
- ros之TF坐标转换
- linux日常学习笔记
- 电视盒子cpu天梯图 电视盒子CPU性能天梯图2022
- 发那科程序全部输出_如何拷贝FANUC系统全部程序
- SQLmap————10、sqlmap详细命令