← 返回 uber 的题目列表Letter Combinations of a Phone Number
类型:qbank
Given a string of digits from 2 to 9, return every possible letter combination it could represent using the classic phone keypad mapping. A standard backtracking exercise with follow-ups on recursion structure versus iterative generation.
Letter Combinations of a Phone Number
Given a string of digits from 2 to 9, return every possible letter combination it could represent using the classic phone keypad mapping. A standard backtracking exercise with follow-ups on recursion structure versus iterative generation.
SWE
medium
backtracking
recursion
string
Frequency
Low
Last asked
2026-03-15
Stage
onsite-coding
Letter Combinations of a Phone Number
Given a string digits containing digits from 2 to 9, return every possible letter combination the number could represent.
Use the classic phone keypad mapping where 2 maps to "abc", 3 maps to "def", 4 maps to "ghi", 5 maps to "jkl", 6 maps to "mno", 7 maps to "pqrs", 8 maps to "tuv", and 9 maps to "wxyz".
Return the combinations in any order. If digits is empty, return an empty array.
Examples
Example 1:
Input: digits = "23"
Output: ["ad","ae","af","bd","be","bf","cd","ce","cf"]
Example 2:
Input: digits = ""
Output: []
Example 3:
Input: digits = "7"
Output: ["p","q","r","s"]
Constraints
0 <= digits.length <= 4
digits[i] is a digit in the range ["2", "9"].
Notes
Expect a follow-up discussion comparing the recursive backtracking structure against an iterative generation approach.