【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. ...
随机推荐
- [转]Oracle数据库中的约束
SQL 约束 约束用于限制加入表的数据的类型. 可以在创建表时规定约束(通过 CREATE TABLE 语句),或者在表创建之后也可以(通过 ALTER TABLE 语句). 我们将主要探讨以下几种约 ...
- 【BZOJ 3036】 绿豆蛙的归宿
求期望的题目(~~~water~~~) 压了下代码,压成15行hhh: 我把代码压成这么丑估计也没有人看吧: 毕竟是zky讲的一个水题,就当给博客除草了: dfs回溯时求当前节点的f,除以当前节 ...
- PLSQL中配置Oracle方法
在服务器上,用PL/SQL连接Oracle数据库时,出现了一个问题,提示: Initialization error Could not load "F:\oracle\bin\oci.dl ...
- POJ1088 滑雪
Description Michael喜欢滑雪百这并不奇怪, 因为滑雪的确很刺激.可是为了获得速度,滑的区域必须向下倾斜,而且当你滑到坡底,你不得不再次走上坡或者等待升降机来载你.Michael想知道 ...
- poj2774 后缀数组 求最长公共子串
Reference:IOI2009论文 http://www.cnblogs.com/ziyi--caolu/p/3192731.html #include "stdio.h" # ...
- Sublime text 快捷键总结
下述快捷键都是我写C++代码时发现的,是否适用其他格式(扩展名)的文件尚为未知. Basic Editing Ctrl + A 全选 Ctrl + S 保存 Ctrl + C 复制 Ctrl + V ...
- 《驾驭Core Data》 第二章 Core Data入门
本文由海水的味道编译整理,请勿转载,请勿用于商业用途. 当前版本号:0.4.0 第二章 Core Data入门 本章将讲解Core Data框架中涉及的基本概念,以及一个简单的Core Data ...
- 点击cell弹出一个日期选择器
- (void)setUpGroup2 { ILGroupItem *group = [[ILGroupItem alloc] init]; // 结束时间 ILSettingItem *endTim ...
- HttpResponse对象
为了响应客户端的请求,同样定义了代表响应的类:HttpResponse类,它也定义在命名空间System.Web下,提供向客户端响应的方法和属性. HttpResponse常用属性和方法 响应对象用于 ...
- Radius 远程用户拨号认证系统
RADIUS 锁定 本词条由“科普中国”百科科学词条编写与应用工作项目 审核 . RADIUS:Remote Authentication Dial In User Service,远程用户拨号认证系 ...