solution.json 1.7 KB
Newer Older
每日一练社区's avatar
每日一练社区 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
{
  "type": "code_options",
  "author": "csdn.net",
  "source": "solution.md",
  "exercise_id": "0ae6182c437147868b6d3b219fa6dd63",
  "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": "java"
    }
  ],
  "prepared": [
    [
      {
        "content": "",
        "language": "java"
      }
    ],
    [
      {
        "content": "",
        "language": "java"
      }
    ],
    [
      {
        "content": "",
        "language": "java"
      }
    ]
  ],
  "template": {
    "content": "\nimport java.util.*;\n\npublic class Solution77 {\n\tList<List<Integer>> output = new LinkedList<>();\n\tint n;\n\tint k;\n\n\tpublic void traceback(int first, LinkedList<Integer> current) {\n\t\tif (current.size() == k) {\n\n\t\t\toutput.add(new LinkedList<Integer>(current));\n\t\t\tSystem.out.println(output);\n\t\t\treturn;\n\t\t}\n\n\t\tfor (int i = first; i <= n; i++) {\n\n\t\t\tcurrent.add(i);\n\t\t\ttraceback(i + 1, current);\n\n\t\t\tcurrent.removeLast();\n\t\t}\n\t}\n\n\tpublic List<List<Integer>> combine(int n, int k) {\n\t\tthis.n = n;\n\t\tthis.k = k;\n\t\ttraceback(1, new LinkedList<>());\n\t\treturn output;\n\t}\n}\n",
    "language": "java"
  },
  "node_id": "dailycode-5d5d68a0fee64164be313bddd528142f",
  "license": "csdn.net",
  "created_at": 1637894159,
  "topic_link": "https://bbs.csdn.net/topics/600470921"
}