We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Difficulty: 中等
Related Topics: 哈希表, 字符串, 回溯
给定一个仅包含数字 2-9 的字符串,返回所有它能表示的字母组合。答案可以按 任意顺序 返回。
2-9
给出数字到字母的映射如下(与电话按键相同)。注意 1 不对应任何字母。
示例 1:
输入:digits = "23" 输出:["ad","ae","af","bd","be","bf","cd","ce","cf"]
示例 2:
输入:digits = "" 输出:[]
示例 3:
输入:digits = "2" 输出:["a","b","c"]
提示:
0 <= digits.length <= 4
digits[i]
['2', '9']
Language: JavaScript
/** * @param {string} digits * @return {string[]} */ var letterCombinations = function (digits) { if (digits.length === 0) return [] const res = [] const map = ['', '', 'abc', 'def', 'ghi', 'jkl', 'mno', 'pqrs', 'tuv', 'wxyz'] const dfs = (curStr, i) => { if (i > digits.length - 1) { res.push(curStr) return } const letters = map[digits[i]] for (const l of letters) { dfs(curStr + l, i + 1) } } dfs('', 0) return res }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
17. 电话号码的字母组合
Description
Difficulty: 中等
Related Topics: 哈希表, 字符串, 回溯
给定一个仅包含数字
2-9
的字符串,返回所有它能表示的字母组合。答案可以按 任意顺序 返回。给出数字到字母的映射如下(与电话按键相同)。注意 1 不对应任何字母。
示例 1:
示例 2:
示例 3:
提示:
0 <= digits.length <= 4
digits[i]
是范围['2', '9']
的一个数字。Solution
Language: JavaScript
The text was updated successfully, but these errors were encountered: