017 Letter Combinations of a Phone Number
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.
|
|
Note:
Although the above answer is in lexicographical order, your answer could be in any order you want.
思路
我们可以利用回溯的方法来解决这道题。
我们不需要改变原有数组,利用标志位‘pos’来标定访问到了哪一层即可。如果采用添加删除的操作,会比较耗时。注意,如果需要跳出回溯,在相应的部分要加入return语句。
|
|