17. Letter Combinations of a Phone Number
来源:互联网 发布:阿里云如何备份 编辑:程序博客网 时间:2024/06/06 00:07
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.
class Solution {public:vector<string> letterCombinations(string digits) {vector<string> phone = { "", "", "abc", "def", "ghi","jkl", "mno", "pqrs", "tuv", "wxyz" };if(digits=="") return res;string tmp;helper(phone, digits, tmp, 0);return res;}private:void helper(vector<string>& phone,string& digits,string& tmp,int cur){if (cur == digits.size()){res.push_back(tmp);return;}for (char c:phone[digits[cur]-'0']){tmp.push_back(c);helper(phone, digits, tmp, cur + 1);tmp.pop_back();}}vector<string> res;};
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
- HDOJ-1873
- Ubuntu下安装matlab出现找不到libXp.so.6错误
- POJ 1363 Rails
- 剑指offer 最小的K个数
- (第18讲)堆排序
- 17. Letter Combinations of a Phone Number
- Office编程 VS操作Office文档
- 自定义生成DBML文件
- 跟着我左手右手一个慢动作,轻松提交AppStore(AppStore提交App流程最新超详细攻略)(填表篇)
- HTTP协议详解(真的很经典)
- poj2253 Frogger(用单源最短路dijkstra的思路求解)
- 最短路径问题/Spfa
- Struts类型转换实现
- php中和mysql数据库相关函数