题目链接
https://leetcode.cn/problems/unique-binary-search-trees/description/
代码
class Solution:
def numTrees(self, n: int) -> int:
dp = [0] * (n + 1)
dp[0] = 1
for i in range(1, n + 1):
for j in range(1, i + 1):
dp[i] += dp[i - j] * dp[j - 1]
return dp[n]