letter-combinations-of-a-phone-number
给一个数字字符串,每个数字代表一个字母,请返回其所有可能的字母组合。
下图的手机按键图,就表示了每个数字可以代表的字母。
您在真实的面试中是否遇到过这个题?
给定 "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相关推荐
- 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 ...
- Letter Combinations of a Phone Number
题目描述: Given a digit string, return all possible letter combinations that the number could represent. ...
- [LeetCode] 17. Letter Combinations of a Phone Number
题目内容 给定一个仅包含数字 2-9 的字符串,返回所有它能表示的字母组合. 给出数字到字母的映射如下(与电话按键相同).注意 1 不对应任何字母. https://leetcode-cn.com/p ...
最新文章
- linux的网络地址配置,教你如何完成Linux网络地址配置
- 【原创】多台电脑如何公用一个键盘鼠标进行操作 - Mouse with Borders 软件
- k8s kafka集群 连接不上_图解 K8s 核心概念和术语
- math.hypot java_Java math
- ASP.Net服务性能优化原则
- Http 四种请求访问代码 HttpGet HttpPost HttpPut HttpDelete .
- 越狱Season 1-Episode 15: By the Skin and the Teeth
- 黑客恶意修改化学成分参数,远程投毒饮用水
- Charles使用教程
- ModelAndView详解
- JVM上篇学习3--内存与垃圾回收
- 分布式集群中网络分区问题
- Proteus常用元件对照表(最全)
- 表贴电阻尺寸与什么有关_贴片电阻、贴片电容规格、封装、尺寸、功率(转)
- Elasticsearch 拼音分词器
- Android之权限(permission)大全
- dnf第七章waiguaⅢ∨dnf第七章好感度【=dnf第七章免费外挂
- Java-给会员打折
- Android Path之Direction.CW、Direction.CCW
- 最近搞的AGV调度控制中心