[LeetCode] 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"].
这题其实不难,注意好递归传入的参数便可以了。
#include <vector>
#include <string>
#include <iostream>
using namespace std; class Solution {
public:
vector<string> letterCombinations(string digits) {
ret.clear();
if(digits.size()<=)
ret.push_back("");
else
help_f(,digits,"");
return ret;
}
vector<string> ret;
vector<vector<char> >mp{{' '},
{},
{'a','b','c'},
{'d','e','f'},
{'g','h','i'},
{'j','k','l'},
{'m','n','o'},
{'p','q','r','s'},
{'t','u','v'},
{'w','x','y','z'}};
void help_f(int nowIdx,string & digits,string curStr)
{
if(nowIdx==digits.size()){
ret.push_back(curStr);
return ;
}
int curNum = int(digits[nowIdx] - '');
for(int i =;i<mp[curNum].size();i++)
help_f(nowIdx+,digits,curStr+mp[curNum][i]);
}
}; int main()
{
Solution sol;
vector<string> ret=sol.letterCombinations("");
for(int i=;i<ret.size();i++)
cout<<ret[i]<<endl;
return ;
}
[LeetCode] Letter Combinations of a Phone Number 回溯的更多相关文章
- LeetCode: Letter Combinations of a Phone Number 解题报告
Letter Combinations of a Phone Number Given a digit string, return all possible letter combinations ...
- [LeetCode]Letter Combinations of a Phone Number题解
Letter Combinations of a Phone Number: Given a digit string, return all possible letter combinations ...
- [LeetCode] 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] 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(bfs)
Given a digit string, return all possible letter combinations that the number could represent. A map ...
- 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 (DFS)
题意 Given a digit string, return all possible letter combinations that the number could represent. A ...
- LeetCode Letter Combinations of a Phone Number 电话号码组合
题意:给一个电话号码,要求返回所有在手机上按键的组合,组合必须由键盘上号码的下方的字母组成. 思路:尼玛,一直RE,题意都不说0和1怎么办.DP解决. class Solution { public: ...
随机推荐
- 六、Linux 文件基本属性
Linux 文件基本属性 Linux系统是一种典型的多用户系统,不同的用户处于不同的地位,拥有不同的权限.为了保护系统的安全性,Linux系统对不同的用户访问同一文件(包括目录文件)的权限做了不同的规 ...
- 引用 Reference
在Java中,判断一个对象是否 "存活" ,都和引用有关,当一个对象没有任何的引用指向它,我们可以认为这个对象可以被GC了. 引用如何定义?Object obj = new Obj ...
- 机顶盒demux的工作原理
在机顶盒中demux部分相对来说是比较复杂的部分,对于机顶盒软件开发的新手来说通常在这里会遇到一些困难,今天特意研究了一下驱动层代码,有一点自己的理解,因此写下来记录一下学习过程. 机顶盒中数据是如何 ...
- Compoer介绍
Compoer介绍 Composer 是 PHP 的一个依赖管理工具.它允许你申明项目所依赖的代码库,它会在你的项目中为你安装他们. 安装Composer Composer.phar 是 Compos ...
- springboot学习资料汇总
收集Spring Boot相关的学习资料,Spring Cloud点这里 推荐博客 纯洁的微笑 程序猿DD liaokailin的专栏 Spring Boot 揭秘与实战 系列 catoop的专栏 简 ...
- hnust 土豪金的加密解密
问题 G: 土豪金的加密与解密 时间限制: 1 Sec 内存限制: 128 MB提交: 466 解决: 263[提交][状态][讨论版] 题目描述 有一位姓金的同学因为买了一部土豪金,从此 ...
- Halcon18 Linux 下载
Halcon18 Linux下载地址:http://www.211xun.com/download_page_14.html HALCON 18 是一套机器视觉图像处理库,由一千多个算子以及底层的数据 ...
- STL之vector使用简介
Vector成员函数 函数 表述 c.assign(beg,end)c.assign(n,elem) 将[beg; end)区间中的数据赋值给c.将n个elem的拷贝赋值给c. c.at(idx) 传 ...
- re.search 与 re.match的区别
search ⇒ find something anywhere in the string and return a match object. match ⇒ find something at ...
- 项目中遇到的ts问题汇总
报错关键词句 报错截图 解决 Declaration of public static field not allowed after declaration of public instance m ...