LeetCode 17. Letter Combinations of a Phone Number
2017-09-11 21:05
609 查看
17. Letter Combinations of a Phone Number
Given a digit string, return all possible letter combinationsthat the number could represent.
A mapping of digit to letters (just like on the telephonebuttons) is given below.
用bfs遍历即可…
代码:
Given a digit string, return all possible letter combinationsthat the number could represent.
A mapping of digit to letters (just like on the telephonebuttons) is given below.
用bfs遍历即可…
代码:
class Solution { public: stringstr[10] = { "", "","abc","def", "ghi","jkl","mno", "pqrs","tuv","wxyz"}; vector<string>res; vector<string>letterCombinations(string digits) { if(digits.size()==0) return res; charans[500]; bfs(digits,0, ans, 0); returnres; } voidbfs(string digits, int digitsIndex, char *ans, int ansIndex) { if(digitsIndex == digits.size()) { ans[ansIndex]= '\0'; stringstr(ans); res.push_back(str); return; } inti = digits[digitsIndex] - '0'; for(int j = 0; j<str[i].size(); j++) { ans[ansIndex]= str[i][j]; bfs(digits,digitsIndex + 1, ans, ansIndex + 1); } } };
相关文章推荐
- 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: Python]17. Letter Combinations of a Phone Number
- LeetCode-17. Letter Combinations of a Phone Number
- 【LeetCode】17. Letter Combinations of a Phone Number
- <LeetCode OJ> 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
- 【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