- 425. Letter Combinations of a Ph
- 5.Letter Combinations of a Phone
- Letter Combinations of a Phone N
- 17. Letter Combinations of a Ph
- Letter Combinations of a Phone N
- 算法练习--LeetCode--17. Letter Combi
- Algorithm-Letter Combinations of
- 017-Letter Combinations of a Pho
- leetcode 17. Letter Combinations
- [leetcode -- backtracking]Combin
Description
Given a digit string excluded '0' and '1', 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.
12
ABC
3
DEF
4
GHI
5
JKL
6
MNO
7
PQRS
8
TUV
9
WXYZ
Although the answer above is in lexicographical order, your answer could be in any order you want.
Example
Example 1:
Input: "23"
Output: ["ad", "ae", "af", "bd", "be", "bf", "cd", "ce", "cf"]
Explanation:
'2' could be 'a', 'b' or 'c'
'3' could be 'd', 'e' or 'f'
Example 2:
Input: "5"
Output: ["j", "k", "l"]
思路:
按照给定的数字先去dict里查找对应的字母, 这里的扩展是按照数字的顺序一层一层往下的,当数字全部走完扩展也就到了最底层,也就达到了返回条件,还有要注意string不是传reference,还有就是循环的时候不用index直接用letter会比较简洁。
代码:
网友评论