题解 | #不同的二叉搜索树(一)#

不同的二叉搜索树(一)

https://www.nowcoder.com/practice/6e5df579ca694d4190304da6406c4dfe

偷个懒,dp以后再说。

#
# 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
#
# 
# @param n int整型 
# @return int整型
#
class Solution:
    def BSTCount(self , n: int) -> int:
        # write code here
        # 卡塔兰数
        # C_n = (2*n*C_n-1)/(n+1)
        # 递归用dp,直接算
        if n == 1:
            return 1
        import math
        # 直接组合数
        catalan = math.comb(2*n, n) // (n+1)
        return catalan

全部评论

相关推荐

陈逸轩1205:才105 哥们在养生呢
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务