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. django之form表单验证

    django中的Form一般有两种功能: 输入html 验证用户输入 #!/usr/bin/env python # -*- coding:utf- -*- import re from django ...

  2. 【GoLang】类型和作用在它上面定义的方法必须在同一个包里定义

    cannot define new methods on non-local type int 参考资料: http://wiki.jikexueyuan.com/project/the-way-to ...

  3. ERROR Cannot determine the location of the VS Common Tools Folder

    参考:ERROR Cannot determine the location of the VS Common Tools Folder   http://blog.csdn.net/m3728975 ...

  4. fstream的使用方法介绍

    转载自:  fstream的使用方法介绍 - saga's blog - C++博客 http://www.cppblog.com/saga/archive/2007/06/19/26652.html ...

  5. 指针 与 数组 以及 a 与 &a的区别

      指针 与数组 并没有什么关系,   指针就是指针,指针变量在32位系统下,永远占4个byte,其值为某一个内存的地址,指针可以指向任何地方,但是不是任何地方你都能通过这个指针变量访问到;   数组 ...

  6. wxPython:事件

    事件──── 是每个 GUI 应用不可舍割的一部分,因为所有的 GUI 应用程序都是基于事件驱动的.从 GUI 程序启动开始,它就回应同户的不同类型的事件.除了用户,也有其它因素可以产生事件,例如:互 ...

  7. http get vs post

    http get vs post GET与POST方法有以下区别:(1) 在客户端,Get方式在通过URL提交数据,数据在URL中可以看到:POST方式,数据放置在HTML HEADER内提交.(2) ...

  8. Kafka单机环境部署

    前面说过Kafka集群环境的部署,现在主要说一下在本地测试中Kafka单机环境的部署,和前面一样首先保证zookeeper服务的正常运行,然后解压并释放kafka安装包,并放到指定位置: tar -x ...

  9. ACM/ICPC 之 数论-斐波拉契●卢卡斯数列(HNNUOJ 11589)

    看到这个标题,貌似很高大上的样子= =,其实这个也是大家熟悉的东西,先给大家科普一下斐波拉契数列. 斐波拉契数列 又称黄金分割数列,指的是这样一个数列:0.1.1.2.3.5.8.13.21.34.… ...

  10. MySQL Got fatal error 1236原因和解决方法【转】

    本文来自:http://blog.itpub.net/22664653/viewspace-1714269/ 一 前言  MySQL 的主从复制作为一项高可用特性,用于将主库的数据同步到从库,在维护主 ...