17. Letter Combinations of a Phone Number
来源:互联网 发布:韩子高网络剧演员表 编辑:程序博客网 时间:2024/06/05 07:53
题目:
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"].
枚举递归
class Solution {public: map<int,string> m={{2,"abc"},{3,"def"},{4,"ghi"},{5,"jkl"},{6,"mno"},{7,"pqrs"},{8,"tuv"},{9,"wxyz"}}; vector<string> letterCombinations(string digits) { vector<string> res; string temp; if(digits.empty()) return res; solve(digits,0,res,temp); return res; } void solve(string digits,int index,vector<string> &res,string temp){ if(index==digits.size()) res.push_back(temp); int i=digits[index]-'0'; for(int j=0;j<m[i].size();j++){ solve(digits,index+1,res,temp+m[i][j]); } }};
阅读全文
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
- hadoop基础概述
- 机器学习汇总
- # 配置CentOS7本地yum源和国内网络yum源
- AndroidStudio-cannot resolve symbol 'Activity'
- 文件系统编程——标准I/O库
- 17. Letter Combinations of a Phone Number
- HDU6092(83/600)
- HDU-1087-Super Jumping! Jumping! Jumping!
- Lua脚本编程
- 我们日常所用得方法解析
- Struts2中Action与Servlet的联系与区别
- VisualStudio工程设置及常见问题
- java设计模式--DAO模式
- Java 的replace替换字符串中的回车换行符的方法