DP
$ 时间复杂度O(N^2),空间复杂度O(N)$
参考文献
lc究极班
AC代码
class Solution {
public:
int numTrees(int n) {
vector<int> f(n + 1);
f[0] = 1;
for (int i = 1 ; i <= n ; i ++){
for (int j = 1 ; j <= i ; j ++){
f[i] += f[j - 1] * f[i - j];
}
}
return f[n];
}
};