題目
原題頁面: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/zh-tw/leetcode-letter-combinations-of-a-phone-number/

