We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
N 个节点的 BST 的形态为 Catalan 数的第 N 项,即 C(2n, n) / (n + 1) => (2n)! / n! / (n + 1),最后可以写成这样:
class Solution { public: int numTrees(int n) { long ans = 1; for (int i = 1; i <= n; ++i) ans += ans * n / i; return ans / (n + 1); } };
The text was updated successfully, but these errors were encountered:
No branches or pull requests
N 个节点的 BST 的形态为 Catalan 数的第 N 项,即 C(2n, n) / (n + 1) => (2n)! / n! / (n + 1),最后可以写成这样:
The text was updated successfully, but these errors were encountered: