Problem
Problem page: https://leetcode.com/problems/letter-combinations-of-a-phone-number/
Topics: Backtracking, String
Difficulty: Medium
Similar problems: (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.
Analysis
The original problem is tagged as recursive backtracking, so maybe that's how we're supposed to solve it. But this is tail recursion, so we can just use a loop instead.
Code
1 | class Solution: |
Article link: https://xnerv.wang/en/leetcode-letter-combinations-of-a-phone-number/

