Letter Combinations of a Phone Number——简单的回溯算法
2024-09-23 03:34:36
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 {
private:
vector<string> res;
string temp;
public:
void getRes(string digits,int len,map<char,string> num_map,int index)
{
if(index>=len)
{
res.push_back(temp);
return;
}
char strNum=digits[index];
string strLetter=num_map[strNum];
for(int j=;j<strLetter.size();j++)
{
temp.push_back(strLetter[j]);
getRes(digits,len,num_map,index+);
temp.pop_back();
} }
vector<string> letterCombinations(string digits) {
map<char,string> num_map;
num_map['']="";
num_map['']="";
num_map['']="abc";
num_map['']="def";
num_map['']="ghi";
num_map['']="jkl";
num_map['']="mno";
num_map['']="pqrs";
num_map['']="tuv";
num_map['']="wxyz";
int len=digits.size();
if(len==)
return res;
getRes(digits,len,num_map,);
return res;
}
};
最新文章
- 转:RealThinClient LinkedObjects Demo解析
- elasticsearch分词插件的安装
- JS 日历控件
- Mysql数据库优化总结2
- [转载]线程间操作无效: 从不是创建控件“ListBox1”的线程访问它
- Visualsvn Server的搭建
- JavaScript Infinite scroll &; Masonry
- 小程序大智慧,sqlserver 注释提取工具
- window.location获取URL中各部分
- Redies安装,修配置,设置密码,
- c# 用户自定义转换
- mysql 计算两点经纬度之间的直线距离(具体sql语句)
- python学习路程1
- [转]golang的goroutine调度机制
- 算法竞赛入门经典-训练指南(10881-Piotr&#39;s Ants)
- 设计模式 笔记 责任链模式 chain of responsibility
- 给TextView加上多彩效果:改变部分字体的大小和颜色
- 问题排查之&#39;org.apache.rocketmq.spring.starter.core.RocketMQTemplate&#39; that could not be found.- Bean method &#39;rocketMQTemplate&#39; in &#39;RocketMQAutoConfiguration&#39; not loaded.
- vsftp服务器同步文件
- UIWindow的windowLevel详解
热门文章
- bzoj1052: [HAOI2007]覆盖问题(二分+构造)
- 开发系统级应用不被Kill
- X210串口配置与stdio移植
- PHP系统编程--01.多进程与多线程
- 安装在Linux下的jenkins执行windows下的bat命令
- 【BZOJ4373】算术天才⑨与等差数列 [线段树]
- 【51NOD-0】1089 最长回文子串 V2(Manacher算法)
- 程序员你为什么这么累? - Controller规范
- HTML5获取地理位置信息并在Google Maps上显示
- lnmp、lamp、lnmpa一键安装包(Updated: 2016-4-12)