题目描述
https://leetcode-cn.com/problems/unique-binary-search-trees/
思路图解
class Solution:
def numTrees(self, n: int) -> int:
# https://leetcode-cn.com/problems/unique-binary-search-trees/solution/hua-jie-suan-fa-96-bu-tong-de-er-cha-sou-suo-shu-b/
dp=[0]*(n+1)
dp[0],dp[1]=1,1
for i in range(2,n+1):
for j in range(1,i+1):
dp[i]+=dp[j-1]*dp[i-j]
# print(dp)
return dp[n]