# LeetCode-Unique Binary Search Trees-解题报告

Given n, how many structurally unique BST's (binary search trees) that store values 1...n?

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        1 2

\ /

2 1

n

/ \

...

class Solution {
public:
int numTrees(int n) {
vector<long long> ans(n + 3, 0);
ans[0] = 1; ans[1] = 1; ans[2] = 2;
for (int i = 3; i < n + 1; ++i)
{
for (int j = 0; j <= i - 1; ++j)
ans[i] += ans[j] * ans[i - j - 1];
}
return ans[n];
}
};

#### LeetCode题解：Convert Sorted Array to Binary Search Tree

2013-11-10 05:26:40

#### LeetCode Convert Sorted List to Binary Search Tree 解题报告

2014-10-01 22:30:08

#### leetcode-java-108. Convert Sorted Array to Binary Search Tree

2016-08-16 14:45:18

#### LeetCode 111 : Minimum Depth of Binary Tree (Java)

2015-12-01 08:19:46

#### Convert Sorted List to Binary Search Tree -- LeetCode

2014-04-17 07:57:02

#### *LeetCode-Unique Binary Search Trees

2015-03-08 11:50:40

#### leetcode-Unique Binary Search Trees:

2015-05-07 15:55:39

#### leetcode-Unique Binary Search Trees

2014-09-29 15:04:04

#### LeetCode-Unique Binary Search Trees

2014-08-06 16:09:00

#### Leetcode-Unique Binary Search Trees

2014-06-05 15:32:35