{
  "type": "code_options",
  "author": "https://github.com/qiyuangong/leetcode",
  "source": "solution.md",
  "exercise_id": "076fa5cfeb7f4adca7fc812b5a58edc5",
  "keywords": "数组,回溯",
  "title": "组合",
  "desc": [
    {
      "content": "\n<p>给定两个整数 <em>n</em> 和 <em>k</em>，返回 1 ... <em>n </em>中所有可能的 <em>k</em> 个数的组合。</p>\n<p><strong>示例:</strong></p>\n<pre><strong>输入:</strong>&nbsp;n = 4, k = 2<strong><br />输出:</strong>[[2,4],[3,4],[2,3],[1,2],[1,3],[1,4],]</pre>",
      "language": "markdown"
    }
  ],
  "answer": [
    {
      "content": "",
      "language": "python"
    }
  ],
  "prepared": [
    [
      {
        "content": "",
        "language": "python"
      }
    ],
    [
      {
        "content": "",
        "language": "python"
      }
    ],
    [
      {
        "content": "",
        "language": "python"
      }
    ]
  ],
  "template": {
    "content": "class Solution(object):\n\tdef combine(self, n, k):\n\t\tres = []\n\t\tself.get_combine(res, [], n, k, 1)\n\t\treturn res\n\tdef get_combine(self, res, prefix, n, k, start):\n\t\tif k == 0:\n\t\t\tres.append(list(prefix))\n\t\telif start <= n:\n\t\t\tprefix.append(start)\n\t\t\tself.get_combine(res, prefix,\n\t\t\t\t\t\t\t n, k - 1, start + 1)\n\t\t\tprefix.pop()\n\t\t\tself.get_combine(res, prefix,\n\t\t\t\t\t\t\t n, k, start + 1)\nif __name__ == \"__main__\":\n\ts = Solution()\n\tprint (s.combine(4, 2))",
    "language": "python"
  },
  "node_id": "dailycode-1cb29400682c421faa8d5b7cb588faef",
  "license": "csdn.net",
  "created_at": 1637894159,
  "topic_link": "https://bbs.csdn.net/topics/600470921"
}