17. Letter Combinations of a Phone Number
2016-12-07 22:22
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.
Although the above answer is in lexicographical order, your answer could be in any order you want.
来自为知笔记(Wiz)
A mapping of digit to letters (just like on the telephone buttons) is given below.
Input: [/b]Digit string "23" Output: [/b]["ad", "ae", "af", "bd", "be", "bf", "cd", "ce", "cf"].Note:[/b]
Although the above answer is in lexicographical order, your answer could be in any order you want.
分析
方法一
每个字母都会独自展开一个分支,就是排列组合问题。DFS搜索 "425"
|
g h i 4
/|\ /|\ /|\ a b c a b c a b c 7 . .
方法二
转自:http://www.tuicool.com/articles/m6BFNfR 可以先将0...1的所有排列找到-->{"a", "b", "c"}再进一步将0...2的所有排列找到-->{"ad", "ae","af", "bd", "be", "bf", "cd", "ce", "cf"}如此循环...直到字符串末尾。实现如下:相关文章推荐
- 17. Letter Combinations of a Phone Number
- leetcode 17. Letter Combinations of a Phone Number
- 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
- Leet Code OJ 17. Letter Combinations of a Phone Number
- 17. Letter Combinations of a Phone Number
- 17. Letter Combinations of a Phone Number
- Leetcode 17. Letter Combinations of a Phone Number
- 17. Letter Combinations of a Phone Number
- LeetCode 17. Letter Combinations of a Phone Number
- 17. Letter Combinations of a Phone Number
- Leetcode 17. Letter Combinations of a Phone Number
- 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