【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. ...
随机推荐
- Java-ArrayList和Vector的区别
这两个类都实现了List接口(List接口继承了Collection接口),他们都是有序集合,即存储在这两个集合中的元素的位置都是有顺序的,相当于一种动态的数组,我们以后可以按位置索引号取出某个元素, ...
- python_元组
元组 元组是用圆括号括起来的,其中的元素之间用逗号隔开.(都是英文半角) >>># 变量引用 str >>> s = "abc" >> ...
- SpringMVC实现一个controller里面有多个方法
我们都知道,servlet代码一般来说只能在一个servlet中做判断去实现一个servlet响应多个请求, 但是springMVC的话还是比较方便的,主要有两种方式去实现一个controller里能 ...
- udp 内网穿透 互发消息
还差实现内网终端,向服务器发送请求,要对方的内网连接自己,实现打洞.在同一网段,或者公网运行,可以相互聊天. 没有实现检测客户端下线功能. 1,服务器代码 package router; import ...
- Stream Byte[] 转换
public byte[] StreamToBytes(Stream stream) { byte[] bytes = new byte[stream.Length]; stream.Read(byt ...
- jquery------捕获异常处理
web.xml <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE web-app PUBLIC ...
- Nonove js timer 计时器
<html> <head> <title> Nonove js timer 计时器 </title> </head> <body> ...
- jquery uploadify 使用
/*进度条框*/ .shangchuantishikuang { border: 7px solid #74A5BF; background-color: white; font-size: 14px ...
- 回家前的挣扎——SQLite增删改查
引言 最后一天,公司就两个人,也不知道弄点什么,就在网上找了Sqlite的文档,看了看,这里也是现学现卖,给自己找点事做,感觉时间过得还是比较快的,不然焦急等待,滋味不好受啊. SQLite简介 SQ ...
- C++中 :: 的意思
表示作用域,和所属关系 ::是运算符中等级最高的,它分为三种:1)global scope(全局作用域符),用法(::name)2)class scope(类作用域符),用法(class::name) ...