[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: ...
随机推荐
- PHP PDO 使用类
PDO类 <?php class MYPDO { protected static $_instance = null; protected $dbName = ''; protected $d ...
- WebSocket 详解
WebSocket 出现前 构建网络应用的过程中,我们经常需要与服务器进行持续的通讯以保持双方信息的同步.通常这种持久通讯在不刷新页面的情况下进行,消耗一定的内存资源常驻后台,并且对于用户不可见.在 ...
- DeepFaceLab报错,CUDA driver is insufficient 解决方法!
DeepFaceLab出错,虽然错误提示很长很长,但是无非两种情况,一种是驱动没装好,一种是显存配置不够. CUDA driver version is insufficient for CUDA r ...
- Redis之String类型操作
接口IRedisDaoStr: package com.net.test.redis.base.dao; import java.util.List; import java.util.Map; /* ...
- Python之路-基础数据类型之字符串
字符串类型 字符串是不可变的数据类型 索引(下标) 我们在日常生活中会遇到很多类似的情况,例如吃饭排队叫号,在学校时会有学号,工作时会有工号,这些就是一种能保证唯一准确的手段,在计算机中也是一样,它就 ...
- Codeforces:68A-Irrational problem(暴力大法好)
A- Irrational problem p Time Limit: 2000MS Memory Limit: 262144K 64bit IO Format: %I64d& %I64 De ...
- django的as_view方法实现分析
django的类视图拥有自动查找指定方法的功能, 通过调用是通过as_view()方法实现 urls.py from meduo_mall.demo import views urlpatterns ...
- 我对于js注入的理解
资料:http://blog.csdn.net/gisredevelopment/article/details/41778671 js注入就是在前端利用使用js的地方 在这其中注入你写的js代码 使 ...
- Spring整合Hibernate与Struts
整合S2SH 一.导入jar包 Spring jar包 Hibernate jar包 Struts2 jar包 以上就是整合需要的所有jar包,当然其中有重复的包,(对比之后去掉版本低的就可以了,还有 ...
- BZOJ 2752:[HAOI2012]高速公路(road)(线段树)
[HAOI2012]高速公路(road) Description Y901高速公路是一条重要的交通纽带,政府部门建设初期的投入以及使用期间的养护费用都不低,因此政府在这条高速公路上设立了许多收费站.Y ...