LeetCode OJ Letter Combinations of a Phone Number
来源:互联网 发布:捡宝贝淘宝u站 编辑:程序博客网 时间:2024/06/17 04:35
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) { possible_val[2] = "abc"; possible_val[3] = "def"; possible_val[4] = "ghi"; possible_val[5] = "jkl"; possible_val[6] = "mno"; possible_val[7] = "pqrs"; possible_val[8] = "tuv"; possible_val[9] = "wxyz"; go = digits; dfs(0); return ans; } void dfs(int pos) { if (pos == go.size()) { ans.push_back(one_ans); return; } else { for (int i = 0; i < possible_val[go[pos] - '0'].size(); i++) { one_ans += possible_val[go[pos] - '0'][i]; dfs(pos + 1); one_ans.erase(pos, 1); } } }private: string go; vector<string> ans; string one_ans; string possible_val[10];};
0 0
- LeetCode OJ:Letter Combinations of a Phone Number
- LeetCode OJ - Letter Combinations of a Phone Number
- LeetCode OJ Letter Combinations of a Phone Number
- LeetCode OJ - Letter Combinations of a Phone Number
- LeetCode OJ-17-Letter Combinations of a Phone Number
- LeetCode OJ-17.Letter Combinations of a Phone Number(DFS)
- 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
- 【BZOJ2438】【中山市选2011】杀人游戏 强连通分量+期望
- Android电话拨号
- 程序员的内功——算法
- LeetCode OJ LRU Cache
- UVa 1647 - Computer Transformation(大数)
- LeetCode OJ Letter Combinations of a Phone Number
- LeetCode OJ Add Two Numbers
- LeetCode OJ Reverse Integer
- COJ--1541: There is No Alternative
- boost xpressive简明用法
- SVN与TortoiseSVN实战:冲突详解(二)
- JAVA创建单例的5中常见方式及比较
- LeetCode OJ Pow(x, n)
- jdbC连接到数据库