[LeetCode] Letter Combinations of a Phone Number
2013-01-28 18:36
393 查看
class Solution { public: vector<string> map; vector<string> ret; vector<char> sln; Solution() { map.push_back(""); map.push_back(""); map.push_back("abc"); map.push_back("def"); map.push_back("ghi"); map.push_back("jkl"); map.push_back("mno"); map.push_back("pqrs"); map.push_back("tuv"); map.push_back("wxyz"); } void DFS(string digits, int n) { if (n == digits.size()) { string s = ""; for (int i = 0; i < sln.size(); i++) s += sln[i]; ret.push_back(s); return; } int pos = digits - '0'; for (int i = 0; i < map[pos].size(); i++) { sln.push_back(map[pos][i]); DFS(digits, n + 1); sln.pop_back(); } } vector<string> letterCombinations(string digits) { // Start typing your C/C++ solution below // DO NOT write int main() function ret.clear(); DFS(digits, 0); return ret; } };
Small Case: 8ms
Large Case: 0ms
相关文章推荐
- 【leetcode】Letter Combinations of a Phone Number
- LeetCode--Letter Combinations of a Phone Number(Python)
- leetcode 17. Letter Combinations of a Phone Number
- 17. Letter Combinations of a Phone Number Leetcode Python
- [Leetcode]Letter Combinations of a Phone Number
- 【Leetcode】Letter Combinations of a Phone Number
- LeetCode Letter Combinations of a Phone Number C++
- 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] Letter Combinations of a Phone Number
- [leetcode][回溯] Letter Combinations of a Phone Number
- LeetCode 17. 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 python
- leetcode 17 Letter Combinations of a Phone Number