题目
原题页面:https://leetcode.com/problems/letter-combinations-of-a-phone-number/
题目类型:Backtracking, String
难度评价:Medium
类似题目:(M) Generate Parentheses, (M) Combination Sum
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.
Input: Digit string "23"
Output: ["ad", "ae", "af", "bd", "be", "bf", "cd", "ce", "cf"].Note:
Although the above answer is in lexicographical order, your answer could be in any order you want.
分析
原题标注类型递归回溯,可能是希望用递归回溯来解决这个问题。但其实这是个尾递归,所以可以直接用循环代替。
代码
1 | class Solution: |
本文地址:https://xnerv.wang/leetcode-letter-combinations-of-a-phone-number/

