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.

思路: hash && dfs.
void dfs(vector<string>& out, string ans, int curDepth, string& digits, string map[10] ){
if(curDepth == digits.length()){
out.push_back(ans);
return;
}
for(int i = 0; i < map[digits[curDepth]-'0'].length(); ++i){
ans.push_back(map[digits[curDepth]-'0'][i]);
dfs(out, ans, curDepth+1, digits, map);
ans.pop_back();
}
} class Solution {
public:
vector<string> letterCombinations(string digits) {
vector<string> out;
string ans;
string map[10] = {"", "", "abc","def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
dfs(out, ans, 0, digits, map);
return out;
}
};

69. Letter Combinations of a Phone Number的更多相关文章

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

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

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

    # -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 17: Letter Combinations of a Phone Numb ...

  4. Letter Combinations of a Phone Number:深度优先和广度优先两种解法

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

  5. leetcode-algorithms-17 Letter Combinations of a Phone Number

    leetcode-algorithms-17 Letter Combinations of a Phone Number Given a string containing digits from 2 ...

  6. 《LeetBook》leetcode题解(17):Letter Combinations of a Phone Number[M]

    我现在在做一个叫<leetbook>的免费开源书项目,力求提供最易懂的中文思路,目前把解题思路都同步更新到gitbook上了,需要的同学可以去看看 书的地址:https://hk029.g ...

  7. Letter Combinations of a Phone Number - LeetCode

    目录 题目链接 注意点 解法 小结 题目链接 Letter Combinations of a Phone Number - LeetCode 注意点 可以不用按字典序排序 解法 解法一:输入的数字逐 ...

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

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

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

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

随机推荐

  1. python3登录极路由并读取宽带帐号帐号密码.py

    python3登录极路由并读取宽带帐号帐号密码,fiddler抓包分析过程略... 步骤:1.登录路由,提取stok. 2.用stok拼成url,post请求 3.解析json数据 代码: " ...

  2. android基础(三)ContentProvider

    ContentProvider主要用于在不同的应用程序之间实现数据共享,它提供了一套完整的机制,允许一个程序访问另一个程序中的数据,同时还能保证被访问数据的安全性,目前内容提供其实android实现跨 ...

  3. Genymotion--最快的安卓模拟器 测试与模拟APP应用必备

    命令行工具,Eclipse插件,多操作系统 1 易于安装,易于运行 超过10个虚拟设备 您很匆忙?您想测试市场的主要设备?使用我们的虚拟设备! 2 控制功能强大的传感器来测试您的应用程序 自定义你的测 ...

  4. Linux的find命令

    使用find命令,可以指定问及那的名称.类别.时间.大小以及权限等,来查找出你想要的文件 语法: fiind  [路径] [参数] [-print] 参数详解: 1.-name  按照文件名查找文件 ...

  5. JQuery源码解析(十一)

    内存泄露 什么是内存泄露? 内存泄露是指一块被分配的内存既不能使用,又不能回收,直到浏览器进程结束.在C++中,因为是手动管理内存,内存泄露是经常出现的事情.而现在流行的C#和Java等语言采用了自动 ...

  6. ActiveXObject函数详解

    什么是 ActiveX 控件? ActiveX 控件广泛用于 Internet.它们可以通过提供视频.动画内容等来增加浏览的乐趣.不过,这些程序可能出问题或者向您提供不需要的内容.在某些情况下,这些程 ...

  7. Oracle数据库初级学习

    第一天 SQL查询语句 CMD——SQLPLUS----账号 soctt 密码 tiger,输入完成后进入SQL数据库,如图显示即连接成功. 连接成功后 ,我们首先设置一下基本界面, --设置 每列显 ...

  8. Android关联源码support-v4,v7,v13源码(转)

    在Android实际开发过程中往往会遇到使用v4,v7或v13兼容包中的一些类如ViewPager,Fragment等,但却无法关联源码. 在网上搜索之后,有很多办法,这里只向大家介绍一种,我用的觉得 ...

  9. web安全之sql注入联合查询

    联合查询的条件: 有显示位.当然要有注入点!! 提前需要了解的函数: union可合并两个或多个select语句的结果集,前提是两个select必有相同列.且各列的数据类型也相同 distinct 去 ...

  10. linux之tmpwatch命令

    系统使用时间长后会产生临时文件(/tmp下),需要清理.但清理的时候不推荐使用rm -rf.这样有时会引起程序的僵死. tmpwatch的说明: [root@AY121231034820cd91077 ...