leetcode---letter-combinations-of-a-phone-number---dfs
2018-01-21 21:08
375 查看
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.
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: void dfs(int dep, string tmp, vector<string> &ans, int n, string digits, string s[]) { if(dep >= n) { ans.push_back(tmp); } int k = digits[dep] - '0'; for(int j=0; j<s[k].size(); j++) dfs(dep+1, tmp+s[k][j], ans, n, digits, s); } vector<string> letterCombinations(string digits) { string s[] = {"", "", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"}; vector<string> ans; int n = digits.size(); string tmp = ""; dfs(0, tmp, ans, n, digits, s); return ans; } };
相关文章推荐
- Leetcode dfs Letter Combinations of a Phone Number
- LeetCode Letter Combinations of a Phone Number DFS
- LeetCode-17 Letter Combinations of a Phone Number(手机拨码-DFS)
- LeetCode-Letter Combinations of a Phone Number-电话号码字母组合-DFS
- DFS深度遍历 leetcode 17 Letter Combinations of a Phone Number
- LeetCode Letter Combinations of a Phone Number (DFS)
- Leetcode Letter Combinations of a Phone Number DFS
- LeetCode Letter Combinations of a Phone Number C++
- 《leetCode》:Letter Combinations of a Phone Number
- LeetCode Online Judge 题目C# 练习 - Letter Combinations of a Phone Number
- leetcode--17. 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解题方案--017--Letter Combinations of a Phone Number
- [LeetCode] Letter Combinations of a Phone Number
- LeetCode解题报告—— Container With Most Water & 3Sum Closest & Letter Combinations of a Phone Number
- Leetcode: Letter Combinations of a Phone Number
- 【Leetcode】【Medium】Letter Combinations of a Phone Number