17. Letter Combinations of a Phone Number
来源:互联网 发布:2016淘宝客导购源码 编辑:程序博客网 时间:2024/06/07 17:32
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.
Subscribe to see whic
static map<char,vector<string>> mm;class Solution { private: int n=0; void init() { mm['0']={" "}; mm['1']={"*"}; mm['2']={"a","b","c"}; mm['3']={"d","e","f"}; mm['4']={"g","h","i"}; mm['5']={"j","k","l"}; mm['6']={"m","n","o"}; mm['7']={"p","q","r","s"}; mm['8']={"t","u","v"}; mm['9']={"w","x","y","z"}; }public: void backtrack(string digits,vector<string>& r1,int k,string temp) { if(temp.size()==digits.size()) { r1.push_back(temp); return ; } else { for(int i=k;i<digits.size();++i) { for(int j=0;j<mm[digits[i]].size();++j) { backtrack(digits,r1,i+1,temp+mm[digits[i]][j]); } } return ; } } vector<string> letterCombinations(string digits) { init(); vector<string> r1; if(digits.empty()) return r1; backtrack(digits,r1,0,""); return r1; }};
h companies asked this question
0 0
- 17.Letter Combinations of a Phone Number
- 17. Letter Combinations of a Phone Number
- 17. Letter Combinations of a Phone Number
- 17. Letter Combinations of a Phone Number
- 17. Letter Combinations of a Phone Number
- 17. Letter Combinations of a Phone Number
- 17. Letter Combinations of a Phone Number
- 17. Letter Combinations of a Phone Number
- 17. Letter Combinations of a Phone Number
- 17. Letter Combinations of a Phone Number
- 17. Letter Combinations of a Phone Number
- 17. Letter Combinations of a Phone Number
- 17. Letter Combinations of a Phone Number
- 17. Letter Combinations of a Phone Number
- 17. Letter Combinations of a Phone Number
- 17. Letter Combinations of a Phone Number
- 17. Letter Combinations of a Phone Number
- 17. Letter Combinations of a Phone Number
- 安卓的SlidingMenu去掉下面的一条线
- 读《利用 Python 进行数据分析》pdf
- LeetCode | Reverse Nodes in k-Group
- springMVC(14)------PathVariable注解
- 每天一个linux命令目录
- 17. Letter Combinations of a Phone Number
- SCU 2096 Maximum Submatrix
- C语言中排序函数的用法
- unity3d 21
- 三个double TO string对比
- 新工必看:工作对于你意味着什么
- Android基础之WebView
- WEB前端 网页图标
- Xcode中的main.m文件与AppDelegate中的代理方法简介---iOS基础篇