leetcode 17. Letter Combinations of a Phone Number
来源:互联网 发布:淘宝卖家聊天术语 编辑:程序博客网 时间:2024/06/03 18:54
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 {map<int, vector<char>>num2char;void init(){num2char[2].push_back('a');num2char[2].push_back('b');num2char[2].push_back('c');num2char[3].push_back('d');num2char[3].push_back('e');num2char[3].push_back('f');num2char[4].push_back('g');num2char[4].push_back('h');num2char[4].push_back('i');num2char[5].push_back('j');num2char[5].push_back('k');num2char[5].push_back('l');num2char[6].push_back('m');num2char[6].push_back('n');num2char[6].push_back('o');num2char[7].push_back('p');num2char[7].push_back('q');num2char[7].push_back('r');num2char[7].push_back('s');num2char[8].push_back('t');num2char[8].push_back('u');num2char[8].push_back('v');num2char[9].push_back('w');num2char[9].push_back('x');num2char[9].push_back('y');num2char[9].push_back('z');}void do_once(vector<string>&re, string digits){vector<string>newre;for (int i = 0; i < re.size(); i++){for (int j = 0; j < num2char[digits[0] - '0'].size(); j++){string str = re[i];str += num2char[digits[0] - '0'][j];newre.push_back(str);}}re = newre;}public:vector<string> letterCombinations(string digits) {vector<string>re;if (digits.empty())return re;init();re.push_back("");while (!digits.empty()){do_once(re, digits);digits.erase(0, 1);}return re;}};
accepted
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
- java中的Arrays类
- C语言库函数四
- Junit
- 二叉排序树的建立和遍历(递归实现)
- 中文中的面向对象
- leetcode 17. Letter Combinations of a Phone Number
- 我的iOS开发入门自学路径
- JS实现鼠标移入移出控制图片的切换效果
- css各种居中
- Problem D: 链表的基本运算(线性表)
- 南阳题目125-盗梦空间
- 《C++》01 数据类型
- 不是人人都懂的学习要点
- Android技术积累:开发规范