【leetcode】Letter Combinations of a Phone Number
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.
回溯法递归调用即可:
class Solution {
public:
vector<string> letterCombinations(string digits) {
vector<string> num2string();
num2string[]="";
num2string[] = "";
num2string[] = "abc";
num2string[] = "def";
num2string[] = "ghi";
num2string[] = "jkl";
num2string[] = "mno";
num2string[] = "pqrs";
num2string[] = "tuv";
num2string[] = "wxyz";
vector<string> result;
string tmp="";
combination(digits,,tmp,num2string,result);
return result;
}
void combination(string &digits,int index,string tmp,vector<string> &num2string,vector<string> &result)
{
if(index==digits.length())
{
result.push_back(tmp);
return;
}
string mapString=num2string[digits[index]-''];
for(int i=;i<mapString.length();i++)
{
tmp.push_back(mapString[i]);
combination(digits,index+,tmp,num2string,result);
tmp.pop_back();
}
}
};
【leetcode】Letter Combinations of a Phone Number的更多相关文章
- 【leetcode】 Letter Combinations of a Phone Number(middle)
Given a digit string, return all possible letter combinations that the number could represent. A map ...
- 【Leetcode】【Medium】Letter Combinations of a Phone Number
Given a digit string, return all possible letter combinations that the number could represent. A map ...
- Leetcode 17. Letter Combinations of a Phone Number(水)
17. Letter Combinations of a Phone Number Medium Given a string containing digits from 2-9 inclusive ...
- 【JAVA、C++】LeetCode 017 Letter Combinations of a Phone Number
Given a digit string, return all possible letter combinations that the number could represent. A map ...
- 【leetcode刷题笔记】Letter Combinations of a Phone Number
Given a digit string, return all possible letter combinations that the number could represent. A map ...
- 【LeetCode】77. Combinations 解题报告(Python & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 方法一:递归 方法二:回溯法 日期 题目地址:htt ...
- [leetcode 17]Letter Combinations of a Phone Number
1 题目: Given a digit string, return all possible letter combinations that the number could represent. ...
- [LeetCode] 17. Letter Combinations of a Phone Number 电话号码的字母组合
Given a string containing digits from 2-9inclusive, return all possible letter combinations that the ...
- Java [leetcode 17]Letter Combinations of a Phone Number
题目描述: Given a digit string, return all possible letter combinations that the number could represent. ...
随机推荐
- 牛客网上的剑指offer题目
题目:在一个二维数组中,每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序.请完成一个函数,输入这样的一个二维数组和一个整数,判断数组中是否含有该整数. 题目:请实现一个函数,将一 ...
- C#获得系统打开的端口和状态
实际是通过c#编程方式调用了CMD命令行,然后调用netstat命令,然后将CMD命令的输出流转到了C#控制台程序上.也可以将结果输出到文件. using System; using System.C ...
- 浅谈php对api开发的作用
最近正在做一个手机APP的服务端API开发,虽然是基于Ruby on Rails的,做的也不太专业,不过大致相通,希望能够给你一些启发. 首先,如果是比较简单的手机APP,例如新闻客户端这样的不会涉及 ...
- 终端terminal配色
切换到~/.bash_profile,无此.bash_profile文件可创建 在文件内粘入以下代码: #enables colorin the terminal bash shell export ...
- pthread clean up
https://www.ibm.com/developerworks/cn/linux/thread/posix_threadapi/part4/ http://www.cnblogs.com/xfi ...
- LWP 轻量级线程的意义与实现
转子 http://www.ibm.com/developerworks/cn/linux/kernel/l-thread/ 二.Linux 2.4内核中的轻量进程实现 最初的进程定义都包含程序.资源 ...
- [Angularjs]ng-switch用法
用法描述 ng-switch根据表达式的值显示或这隐藏对应部分.类似c#或者其他预览里面的switch用法.可以慢慢体会. 说道ng-switch就要说到子元素该怎么根据当前值进行变化.子元素可以通过 ...
- 百度文库,linux下安装oracle客户端
linux单独安装oracle client(oracle客户端) 更新:2013-10-17 18:30 | 标签:linux oracle 1.要远程使用oracle,先下载下面三个文件,注意 ...
- httpd/php/mysql的安装-1
rely: 依赖: relier, reliance , reliable : i don't think he is a reliable man . we must lay stress on ...
- (ヒトコト)一个挺有趣的东西!作为一个动漫宅,游戏宅来说还是一个挺有趣的接口!banner上面就是
Hitokoto API 更新:2014.02.22 问题/反馈:api # hitokoto.us 数据获取:[ 数据获取 ] 调用举例:[ JavaScript + HTML (同步) ] [ J ...