{
  "type": "code_options",
  "author": "csdn.net",
  "source": "solution.md",
  "exercise_id": "baa3bacd331e4371b700887e567f1fa3",
  "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": "cpp"
    }
  ],
  "prepared": [
    [
      {
        "content": "",
        "language": "cpp"
      }
    ],
    [
      {
        "content": "",
        "language": "cpp"
      }
    ],
    [
      {
        "content": "",
        "language": "cpp"
      }
    ]
  ],
  "template": {
    "content": "class Solution\n{\npublic:\n\tvector<string> letterCombinations(string digits)\n\t{\n\t\tvector<string> nummap({\" \",\n\t\t\t\t\t\t\t   \"\",\n\t\t\t\t\t\t\t   \"abc\",\n\t\t\t\t\t\t\t   \"def\",\n\t\t\t\t\t\t\t   \"ghi\",\n\t\t\t\t\t\t\t   \"jkl\",\n\t\t\t\t\t\t\t   \"mno\",\n\t\t\t\t\t\t\t   \"pqrs\",\n\t\t\t\t\t\t\t   \"tuv\",\n\t\t\t\t\t\t\t   \"wxyz\"});\n\t\tvector<string> rs;\n\t\tvector<string> empty;\n\t\tif (digits.size() == 0)\n\t\t\treturn empty;\n\t\tfor (auto d : digits)\n\t\t{\n\t\t\tif (d == '0')\n\t\t\t\treturn empty;\n\t\t\tif (d == '1')\n\t\t\t\treturn empty;\n\t\t\tauto &s = nummap[d - '0'];\n\t\t\tif (s.size() == 0)\n\t\t\t\tcontinue;\n\t\t\tif (rs.size() == 0)\n\t\t\t\tfor (auto c : s)\n\t\t\t\t{\n\t\t\t\t\tstring t;\n\t\t\t\t\tt.push_back(c);\n\t\t\t\t\trs.emplace_back(t);\n\t\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tvector<string> rn;\n\t\t\t\tfor (auto c : s)\n\t\t\t\t{\n\t\t\t\t\tfor (auto r : rs)\n\t\t\t\t\t{\n\t\t\t\t\t\tr.push_back(c);\n\t\t\t\t\t\trn.emplace_back(std::move(r));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tstd::swap(rs, rn);\n\t\t\t}\n\t\t}\n\t\treturn rs;\n\t}\n};",
    "language": "cpp"
  },
  "node_id": "dailycode-11e24a6aacb34945ba8db8b0a1f76088",
  "license": "csdn.net",
  "created_at": 1637894158,
  "topic_link": "https://bbs.csdn.net/topics/600471003"
}