【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. ...
随机推荐
- HTML5 文件操作API
简介 我常常想,如果网络应用能够读取和写入文件与目录,将会非常方便.从离线转移到在线后,应用变得更加复杂,而文件系统方面的API的缺乏也一直阻碍着网络前进.存储二进制数据或与其进行交互不应局限于桌面. ...
- Spring 作用域 scope
spring的作用域将对Bean的生命周期和创建方式产生影响. 主要分为五种类型的作用域 singleton (默认)在spring IOC容器中仅存在一个Bean实例,Bean以单实例的方式存在. ...
- PLSQL导入Excel表中数据
PL/SQL 和SQL Sever导入excel数据的原理类似,就是找到一个导入excel数据的功能项,按照步骤走就是了.下面是一个些细节过程,希望对像我这样的菜鸟有帮助. www.2cto.co ...
- SQL增加、删除、更改表中的字段名
1. 向表中添加新的字段 ) not null 2. 删除表中的一个字段 delete table table_name column column_name 3. 修改表中的一个字段名 alter ...
- intent属性
private String mAction;private Uri mData;private String mType;private String mPackage;private Compon ...
- android button 函数调用栈
Button button=(Button) findViewById(R.id.button);button.setOnClickListener(new Button.OnClickListene ...
- mysql随机获取一条或者多条数据
原文地址:http://www.im286.com/thread-7091552-1-1.html 转来备份 研究一些随机的因素,主要是讲究效率问题. 语句一: MYSQL手册里面针对RAND()的提 ...
- Adele的生活
3个小时的电影,有点冗长,中间抽空吃了个饭,跑出去抽了3根烟,接着洗了个脸才回来接着看完,法国人做事真是拖沓啊有木有. 电影看完后给人一种淡淡的忧伤,第一次了解lesbians的真实世界(如果电影是来 ...
- table设置滚动条
.table {display: block;height:300px;overflow-y:auto;} 在bootstrap的Modal中使用此设置,可能会父容器溢出,但不会显示出来,会在页面侧边 ...
- Java finally语句到底是在return之前还是之后执行?
网上有很多人探讨Java中异常捕获机制try...catch...finally块中的finally语句是不是一定会被执行?很多人都说不是,当然他们的回答是正确的,经过我试验,至少有两种情况下fina ...