solution.json 1.9 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": "57af5c6123504bd884409d603dd5f7f3",
  "keywords": "字符串,动态规划,回溯",
  "title": "括号生成",
  "desc": [
    {
      "content": "\n<p>数字 <code>n</code> 代表生成括号的对数,请你设计一个函数,用于能够生成所有可能的并且 <strong>有效的 </strong>括号组合。</p><p> </p><p><strong>示例 1:</strong></p><pre><strong>输入:</strong>n = 3<strong><br />输出:</strong>[\"((()))\",\"(()())\",\"(())()\",\"()(())\",\"()()()\"]</pre><p><strong>示例 2:</strong></p><pre><strong>输入:</strong>n = 1<strong><br />输出:</strong>[\"()\"]</pre><p> </p><p><strong>提示:</strong></p><ul>\t<li><code>1 <= n <= 8</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\tvoid gen(string &p, int lc, int rc, vector<string> &r, int n)\n\t{\n\t\tif (lc > n)\n\t\t\treturn;\n\t\tif (lc == n && rc == n)\n\t\t{\n\t\t\tr.push_back(p);\n\t\t\treturn;\n\t\t}\n\t\tp.push_back('(');\n\t\tlc++;\n\t\tgen(p, lc, rc, r, n);\n\t\tp.pop_back();\n\t\tlc--;\n\t\tif (lc > rc)\n\t\t{\n\t\t\tp.push_back(')');\n\t\t\trc++;\n\t\t\tgen(p, lc, rc, r, n);\n\t\t\tp.pop_back();\n\t\t\trc--;\n\t\t}\n\t}\n\tvector<string> generateParenthesis(int n)\n\t{\n\t\tstring p;\n\t\tint lc = 0, rc = 0;\n\t\tvector<string> r;\n\t\tgen(p, lc, rc, r, n);\n\t\treturn r;\n\t}\n};",
    "language": "cpp"
  },
  "node_id": "dailycode-9399618c5b70447fa35668bbe36d2da8",
  "license": "csdn.net",
  "created_at": 1637894158,
  "topic_link": "https://bbs.csdn.net/topics/600470115"
}