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.

好长时间没练题了,最近比较懒加之工作略忙,疏于思考,浪费了很多时间。这题想来想去知道是要深搜,但是都没动手实现,以为很复杂,其实是很典型的DFS模板,这和 Sudoku solver 的思路基本没有差别(其实和所有类似的题型都没差,几乎都用DFS模板一套就能出来)

void comboIter(string digits, int i, vector<string> &domains, string cur, vector<string> &result) {
if (i >= digits.size()) {
result.push_back(cur);
return;
}
char t = digits.at(i);
string domain = domains[t-''];
string old = cur;
for (char ele : domain) {
cur += ele;
comboIter(digits, i+, domains, cur ,result);
cur = old;
}
} vector<string> letterCombinations(string digits) {
vector<string> ret;
if (!digits.size()) return {""};
vector<string> domain = {"","","abc","def","ghi","jkl","mno","pqr","stu","vwxyz"};
comboIter(digits,,domain,"",ret);
return ret;
}

[LeetCode] Letter Combinations of a Phone Number的更多相关文章

  1. LeetCode: Letter Combinations of a Phone Number 解题报告

    Letter Combinations of a Phone Number Given a digit string, return all possible letter combinations ...

  2. [LeetCode]Letter Combinations of a Phone Number题解

    Letter Combinations of a Phone Number: Given a digit string, return all possible letter combinations ...

  3. [LeetCode] Letter Combinations of a Phone Number 电话号码的字母组合

    Given a digit string, return all possible letter combinations that the number could represent. A map ...

  4. LeetCode——Letter Combinations of a Phone Number

    Given a digit string, return all possible letter combinations that the number could represent. A map ...

  5. [LeetCode] Letter Combinations of a Phone Number(bfs)

    Given a digit string, return all possible letter combinations that the number could represent. A map ...

  6. LeetCode Letter Combinations of a Phone Number (DFS)

    题意 Given a digit string, return all possible letter combinations that the number could represent. A ...

  7. [LeetCode] Letter Combinations of a Phone Number 回溯

    Given a digit string, return all possible letter combinations that the number could represent. A map ...

  8. LeetCode Letter Combinations of a Phone Number 电话号码组合

    题意:给一个电话号码,要求返回所有在手机上按键的组合,组合必须由键盘上号码的下方的字母组成. 思路:尼玛,一直RE,题意都不说0和1怎么办.DP解决. class Solution { public: ...

  9. leetcode Letter Combinations of a Phone Number python

    class Solution(object): def letterCombinations(self, digits): """ :type digits: str : ...

随机推荐

  1. 在Navicat for MySQL中打开视图时,提示视图没有主键的问题

    一直把视图理解为一个select语句而已,视图一般就是用于查询,不会通过视图来更新表或视图本身的数据,所以视图根本不需要什么主键.今天自己建了一个视图view_test: drop view if e ...

  2. linux创建子进程--fork()方法

    (1)fork()的定义 fork()函数是Unix中派生新进程的唯一方法,声明如下: #include <unistd.h> pid_t fork(void); 我们需要理解的是,调用一 ...

  3. window.navigate 与 window.location.href 的使用区别介绍

    window.navigate(sURL)方法是针对IE的,不适用于FF,在HTML DOM Window Object中,根本没有列出window.navigate方法. 要在javascript中 ...

  4. sharepoint定义固定的网站集

    SPSite site = new SPSite(http://192.168.0.3/);            SPWeb web = site.RootWeb;

  5. http apr 8080 exec 3解决

    IDEA运行tomcat,总是出现这个错误. 解决: 在tomcat的配置里,加上下面这句话: -Xms256m -Xmx512m -XX:MaxNewSize=64m -XX:MaxPermSize ...

  6. Appium+Robotframework实现Android应用的自动化测试-6:一个简单的例子

    万事具备,只欠编码! 下面看一个简单的示例,这个示例验证Android手机自带的通讯录的添加联系人的操作是否成功.这个例子是Appium官网自带的示例,有兴趣的同学也可以自己下载来研究和学习,下载地址 ...

  7. Unity3d《Shader篇》绘制圆角图片

    Pass { CGPROGRAM // Upgrade NOTE: excluded shader from OpenGL ES 2.0 because it does not contain a s ...

  8. storm单机环境部署

    前面说过storm集群的部署,这篇主要介绍storm单机环境部署,其实他们之间很类似,就是将之前配置文件中所有的集群条目改成本机的地址即可,部署之前应该按前面solr和zookeeper单机环境部署那 ...

  9. cxGrid 增加序号 (非数据库绑定模式) (测试通过)

    cxGrid 增加序号 (非数据库绑定模式) ----------------------------------- 1. 选在 adoQuery 控件 , 鼠标右键菜单中 选择 Fields Edi ...

  10. cxGrid 速度

    在做AdoHelper实用程序的时候,我用了DevExpress的cxGrid控件.在此之前用的是dbgrid,考虑到不能把所有的数据都拉到本地,我用了动态生成的select top 500的命令.这 ...