题目链接:https://leetcode.com/problems/unique-binary-search-trees/
题目:
BST's
For example,
Given n = 3, there are a total of 5 unique BST's.
1 3 3 2 1
\ / / / \ \
3 2 1 1 3 2
/ / \ \
2 1 2 3
思路:
看到题目半天没思路。。看了别人的题解才反应过来。。参考博文:点击打开链接
算法:
1. public int numTrees(int n) {
2. int f[] = new int[n + 1];
3. 0] = 1;
4. for (int i = 1; i <= n; i++) {
5. for (int j = 0; j < i; j++)
6. 1 - j];
7. }
8. return f[n];
9. }