{ "type": "code_options", "author": "https://github.com/begeekmyfriend/leetcode", "source": "solution.md", "exercise_id": "b83b2c495c46406e8776d85e98306307", "keywords": "树,二叉搜索树,数学,动态规划,二叉树", "title": "不同的二叉搜索树", "desc": [ { "content": "\n
\n

给你一个整数 n ,求恰由 n 个节点组成且节点值从 1n 互不相同的 二叉搜索树\n有多少种?返回满足题意的二叉搜索树的种数。

", "language": "markdown" }, { "content": "\n

 

", "language": "markdown" }, { "content": "\n

示例 1:

\n\n
输入:n = 3\n输出:5\n
", "language": "markdown" }, { "content": "\n

示例 2:

", "language": "markdown" }, { "content": "\n
输入:n = 1\n输出:1\n
", "language": "markdown" }, { "content": "\n

 

", "language": "markdown" }, { "content": "\n

提示:

", "language": "markdown" }, { "content": "\n\n
", "language": "markdown" } ], "answer": [ { "content": "", "language": "cpp" } ], "prepared": [ [ { "content": "", "language": "cpp" } ], [ { "content": "", "language": "cpp" } ], [ { "content": "", "language": "cpp" } ] ], "template": { "content": "#include \nusing namespace std;\nclass Solution\n{\npublic:\n\tint numTrees(int n)\n\t{\n\t\tvector sum(n + 1);\n\t\tsum[0] = 1;\n\t\tfor (int i = 1; i <= n; i++)\n\t\t{\n\t\t\tfor (int j = 0; j < i; j++)\n\t\t\t{\n\t\t\t\tsum[i] += sum[j] * sum[i - j - 1];\n\t\t\t}\n\t\t}\n\t\treturn sum[n];\n\t}\n}", "language": "cpp" }, "node_id": "dailycode-86063bc2e4f9408c90a68336b7d0b233", "license": "csdn.net", "created_at": 1637894158, "topic_link": "https://bbs.csdn.net/topics/600469926" }