[LeetCode]Unique Binary Search Trees 唯一BST数量
Unique Binary Search Trees 唯一BST数量
class Solution(object):
def numTrees(self, n):
"""
:type n: int
:rtype: int
"""
dp = [0] * (n + 1)
dp[0] = dp[1] = 1
for i in range(2, n+1):
for j in range(i):
dp[i] += dp[j] * dp[i-j-1]
return dp[n]
![](https://i.loli.net/2018/11/17/5beff4d639cbb.jpg)
关注公众号:数据结构与算法那些事儿,每天一篇数据结构与算法