{
  "type": "code_options",
  "author": "csdn.net",
  "source": "solution.md",
  "exercise_id": "02e1c1c9c9a54a26ba43bc933e73b77f",
  "keywords": "哈希表,字符串,回溯",
  "title": "电话号码的字母组合",
  "desc": [
    {
      "content": "\n<p>给定一个仅包含数字 <code>2-9</code> 的字符串，返回所有它能表示的字母组合。答案可以按 <strong>任意顺序</strong> 返回。</p><p>给出数字到字母的映射如下（与电话按键相同）。注意 1 不对应任何字母。</p><p><img src=\"https://cdn.jsdelivr.net/gh/doocs/leetcode@main/solution/0000-0099/0017.Letter%20Combinations%20of%20a%20Phone%20Number/images/17_telephone_keypad.png\" style=\"width: 200px;\" /></p><p> </p><p><strong>示例 1：</strong></p><pre><strong>输入：</strong>digits = \"23\"<strong><br />输出：</strong>[\"ad\",\"ae\",\"af\",\"bd\",\"be\",\"bf\",\"cd\",\"ce\",\"cf\"]</pre><p><strong>示例 2：</strong></p><pre><strong>输入：</strong>digits = \"\"<strong><br />输出：</strong>[]</pre><p><strong>示例 3：</strong></p><pre><strong>输入：</strong>digits = \"2\"<strong><br />输出：</strong>[\"a\",\"b\",\"c\"]</pre><p> </p><p><strong>提示：</strong></p><ul>\t<li><code>0 <= digits.length <= 4</code></li>\t<li><code>digits[i]</code> 是范围 <code>['2', '9']</code> 的一个数字。</li></ul>",
      "language": "markdown"
    }
  ],
  "answer": [
    {
      "content": "",
      "language": "python"
    }
  ],
  "prepared": [
    [
      {
        "content": "",
        "language": "python"
      }
    ],
    [
      {
        "content": "",
        "language": "python"
      }
    ],
    [
      {
        "content": "",
        "language": "python"
      }
    ]
  ],
  "template": {
    "content": "from typing import List\nclass Solution:\n\tdef letterCombinations(self, digits: str) -> List[str]:\n\t\tletters = [\n\t\t\t[],\n\t\t\t[],\n\t\t\t['a', 'b', 'c'],\n\t\t\t['d', 'e', 'f'],\n\t\t\t['g', 'h', 'i'],\n\t\t\t['j', 'k', 'l'],\n\t\t\t['m', 'n', 'o'],\n\t\t\t['p', 'q', 'r', 's'],\n\t\t\t['t', 'u', 'v'],\n\t\t\t['w', 'x', 'y', 'z'],\n\t\t]\n\t\tcombinations = []\n\t\ti = 0\n\t\tfor d in digits:\n\t\t\tletter = letters[int(d)]\n\t\t\tif i == 0:\n\t\t\t\tfor l in letter:\n\t\t\t\t\tcombinations.append([l])\n\t\t\telse:\n\t\t\t\tadded = []\n\t\t\t\tfor c in combinations:\n\t\t\t\t\tj = 0\n\t\t\t\t\torigin_c = []\n\t\t\t\t\torigin_c += c\n\t\t\t\t\tfor l in letter:\n\t\t\t\t\t\tif j == 0:\n\t\t\t\t\t\t\tc.append(l)\n\t\t\t\t\t\telse:\n\t\t\t\t\t\t\tnew_c = []\n\t\t\t\t\t\t\tnew_c += origin_c\n\t\t\t\t\t\t\tnew_c.append(l)\n\t\t\t\t\t\t\tadded.append(new_c)\n\t\t\t\t\t\tj += 1\n\t\t\t\tcombinations += added\n\t\t\ti += 1\n\t\toutput = []\n\t\tfor c in combinations:\n\t\t\toutput.append(''.join(c))\n\t\treturn output\n# %%\ns = Solution()\nprint(s.letterCombinations(digits = \"23\"))",
    "language": "python"
  },
  "node_id": "dailycode-62b760478e454f309a425bf1da91ecd9",
  "license": "csdn.net",
  "created_at": 1637894159,
  "topic_link": "https://bbs.csdn.net/topics/600471003"
}