[Leetcode 47] 17 Letter Combinations of a Phone Number
2013-05-25 13:08
429 查看
Problem:
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.
View Code
Attention:
There are many C++ skills used in this code, learn it.
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.
class Solution { public: vector<string> table; vector<string> res; vector<string> letterCombinations(string digits) { // Start typing your C/C++ solution below // DO NOT write int main() function if (digits.size() == 0) return vector<string>(1,""); res.clear(); table.resize(10); table[2] = "abc"; table[3] = "def"; table[4] = "ghi"; table[5] = "jkl"; table[6] = "mno"; table[7] = "pqrs"; table[8] = "tuv"; table[9] = "wxyz"; backtrack(digits, 0, ""); return res; } void backtrack(string &s, int pos, string ss) { if (pos == s.size()) { res.push_back(ss); return ; } for (int i=0; i<table[s[pos] - '0'].size(); i++) { backtrack(s, pos+1, ss+table[s[pos] - '0'][i]); } return ; } };
View Code
Attention:
There are many C++ skills used in this code, learn it.
相关文章推荐
- 【leetcode】【17】Letter Combinations of a Phone Number
- LeetCode17 Letter Combinations of a Phone Number
- LeetCode - 17 - Letter Combinations of a Phone Number
- LeetCode | #17 Letter Combinations of a Phone Number
- leetcode 17-Letter Combinations of a Phone Number
- LeetCode 17 Letter Combinations of a Phone Number
- [LeetCode]17 Letter Combinations of a Phone Number
- LeetCode 17_Letter Combinations of a Phone Number
- [leetcode-17]Letter Combinations of a Phone Number(java)
- [leetcode 17]Letter Combinations of a Phone Number
- [Leetcode] #17 Letter Combinations of a Phone Number
- LeetCode 17: Letter Combinations of a Phone Number
- LeetCode 17 Letter Combinations of a Phone Number(C,C++,Java,Python)
- LeetCode-17-Letter-Combinations-of-a-Phone-Number 递归+模拟
- LeetCode 17 Letter Combinations of a Phone Number
- [leetcode 17] Letter Combinations of a Phone Number
- leetcode——17——Letter Combinations of a Phone Number
- leetcode 17 Letter Combinations of a Phone Number
- leetcode 17: Letter Combinations of a Phone Number
- 17. Letter Combinations of a Phone Number LeetCode题解