topic:
Topic links: https://leetcode-cn.com/problems/unique-binary-search-trees/
Problem-solving ideas:
The number of different types of binary search, in line with Cattleya number, also known as Catalan number , general term formula is:
Directly into the formula, you can obtain any of
Code:
class Solution:
def numTrees(self, n: int) -> int:
res = 1
for i in range(n):
res = res * 2 * (2 * i + 1) // (i + 2)
return res