题目链接:https://leetcode-cn.com/problems/unique-binary-search-trees/
难度:中等
描述:
给你一个整数 n ,求恰由 n 个节点组成且节点值从 1 到 n 互不相同的 二叉搜索树 有多少种?返回满足题意的二叉搜索树的种数。
题解
思路:
class Solution:def numTrees(self, n: int) -> int:r = [0] * (n + 1)r[0], r[1] = 1, 1for i in range(2, n+1):for j in range(1, i+1):r[i] += r[j-1] * r[i-j]return r[n]
