96. Unique Binary Search Trees
问题描述
Given n, how many structurally unique BST’s (binary search trees) that store values 1 … n?
Input: 3
Output: 5
Explanation:
Given n = 3, there are a total of 5 unique BST’s:
问题很直观,设置dp[i]表示给定i个数字可以构成多少个,把给定的数字拆成左右两个部分,子树结果相乘就是总的个数。
error:
这里犯了一个很典型的错误,一开始简单的直接就用递归去写了,但是进一步分析发现我们想要计算n,要基于所有