LeetCode Letter Combinations of a Phone Number
来源:互联网 发布:手机短信群发软件 编辑:程序博客网 时间:2024/06/07 17:18
题目:
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) {ans.clear();createDic();dfs(0, digits.size(), digits);return ans;}private://建立映射关系unordered_map<char, vector<char>> dic;vector<string> ans;char a[1000];void createDic() {dic['2'].push_back('a');dic['2'].push_back('b'); dic['2'].push_back('c');dic['3'].push_back('d');dic['3'].push_back('e');dic['3'].push_back('f');dic['4'].push_back('g');dic['4'].push_back('h');dic['4'].push_back('i');dic['5'].push_back('j');dic['5'].push_back('k');dic['5'].push_back('l');dic['6'].push_back('m');dic['6'].push_back('n');dic['6'].push_back('o');dic['7'].push_back('p');dic['7'].push_back('q');dic['7'].push_back('r');dic['7'].push_back('s');dic['8'].push_back('t');dic['8'].push_back('u');dic['8'].push_back('v');dic['9'].push_back('w');dic['9'].push_back('x');dic['9'].push_back('y');dic['9'].push_back('z');}void dfs(int dep, int maxDep, string &digits) {if (dep == maxDep) {string s;for (int i = 0; i < maxDep; i++)s.push_back(a[i]);ans.push_back(s);}for (int i = 0; i < dic[digits[dep]].size(); i++) {a[dep] = dic[digits[dep]][i];dfs(dep + 1, maxDep, digits);}}};
0 0
- LeetCode: Letter Combinations of a Phone Number
- LeetCode Letter Combinations of a Phone Number
- LeetCode: Letter Combinations of a Phone Number
- [Leetcode] Letter Combinations of a Phone Number
- [LeetCode] Letter Combinations of a Phone Number
- 【leetcode】Letter Combinations of a Phone Number
- LeetCode: Letter Combinations of a Phone Number
- [LeetCode]Letter Combinations of a Phone Number
- LeetCode-Letter Combinations of a Phone Number
- [LeetCode] Letter Combinations of a Phone Number
- LeetCode - Letter Combinations of a Phone Number
- LeetCode:Letter Combinations of a Phone Number
- LeetCode | Letter Combinations of a Phone Number
- leetcode Letter Combinations of a Phone Number
- Leetcode: Letter Combinations of a Phone Number
- 【leetcode】Letter Combinations of a Phone Number
- [LeetCode] Letter Combinations of a Phone Number
- leetcode: Letter Combinations of a Phone Number
- OpenCms中文网 开通了
- 查询最大前几位或最小前几位 排序(简单笔记)
- 虚函数与多态性,虚拟继承,纯虚函数及重载、覆盖、隐藏的区别
- JS 清除字符串数组中,重复元素
- chromium for android GPU进程结构分析
- LeetCode Letter Combinations of a Phone Number
- ArcGIS教程:如何轻松的使用图例图面形状
- Linux(ubuntu)下30天自制os学习引导,第3.1天(如何得到 u盘的chs结构)
- HTMLParser使用详解(1)- 初始化Parser
- 从应用示例来认识Tiny框架
- hdu 1292 "下沙野骆驼"ACM夏令营
- ECSHOP常用修改
- MySql状态查看方法_MySql如何查看连接数和状态
- 黑马程序员 多线程