[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监控二之cacti简单安装部署
目录 cacti简单部署 1 环境依赖包部署 1 1. cacti中文版0.8e搭建 2 2. cacti安装向导 url:http://192.168.200.243/ ...
- cmf5分页相关
//分页配置在app/config.php 'paginate' => [ 'type' => '\cmf\paginator\Bootstrap', 'var_page' => ' ...
- JAVA使用JDBC连接,修改MySQL数据库(比较乱)
原文地址1(连接MySQL图文) : http://www.cnblogs.com/GarfieldEr007/p/5746137.html 原文地址2 (修改MySQL图文): http://www ...
- BFS:胜利大逃亡
解题心得: 1.水题,主要主意好一个点就好. 2.注意x.y.z坐标的选取就好. 题目: Ignatius被魔王抓走了,有一天魔王出差去了,这可是Ignatius逃亡的好机会. 魔王住在一个城堡里,城 ...
- 内容提供器(Content Provider)
一个跟数据库很相似的用于与其他程序传递信息的组件,用的也是数据库的CRUD操作 相关权限 注册内容提供者以及权限 <provider android:name=".ContentRes ...
- 给B公司的一些建议(又一篇烂尾的文章)
感慨:太多太多的悲伤故事,发生在自己身上,发生在自己的身边.因此,为了避免总是走"弯路",走"错误"的道路,最近一直在完善自己的理论模型. 烂尾说明:本文是一篇 ...
- P3116 [USACO15JAN]会议时间Meeting Time
P3116 [USACO15JAN]会议时间Meeting Time 题目描述 Bessie and her sister Elsie want to travel from the barn to ...
- [2016-04-19 15:46:03 - IceHoloReader1.0] Installation error: INSTALL_FAILED_CONFLICTING_PROVIDER [20
[2016-04-19 15:46:03 - IceHoloReader1.0] Installation error: INSTALL_FAILED_CONFLICTING_PROVIDER [20 ...
- 【POI 2010】反对称 Antisymmetry
题目: 对于一个 $0/1$ 字符串,如果将这个字符串 $0$ 和 $1$ 取反后,再将整个串反过来和原串一样,就称作「反对称」字符串.比如 $00001111$ 和 $010101$ 就是反对称的, ...
- Windows网络编程笔记5 -- 其他套接字
包括红外线套接字(IrSock).IPX/SPX 套接字.NetBIOS 套接字.AppleTalk 套接字.ATM 套接字等.对这些套接字进行简单介绍. 第一.红外线套接字(I r S o c k) ...