# leetcode 96. 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


public class Solution {
public int numTrees(int n) {
int[] dp=new int[n+1];
dp[0]=1;
dp[1]=1;
for(int level=2;level<=n;level++)
for(int root=1;root<=level;root++){
dp[level]+=dp[level-root]*dp[root-1];
}
return dp[n];
}
}
• 本文已收录于以下专栏：

## LeetCode 96. Unique Binary Search Trees 解题报告

LeetCode 108. Convert Sorted Array to Binary Search Tree 解题报告

## <LeetCode OJ> 96. Unique Binary Search Trees

96. Unique Binary Search Trees My Submissions Question Total Accepted: 75913 Total Submissions: ...

## [leetcode]96. Unique Binary Search Trees(Java)

https://leetcode.com/problems/unique-binary-search-trees/#/description Given n, how many ...

## leetcode_middle_45_96. Unique Binary Search Trees

• pusude
• 2017年02月15日 14:08
• 109

## LeetCode 95, 96. Unique Binary Search Trees i. ii

1. 题目描述 95.Given n, generate all structurally unique BST’s (binary search trees) that store values...

## LeetCode --- 96. Unique Binary Search Trees

• makuiyu
• 2015年04月14日 19:49
• 655

## leetcode 95&96. Unique Binary Search Trees

96. Unique Binary Search Trees Given n, how many structurally unique BST's (binary search trees) tha...

举报原因： 您举报文章：leetcode 96. Unique Binary Search Trees 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)