LintCode:不同的二叉查找树

LintCode:不同的二叉查找树

思路见这篇博客

class Solution:
    # @paramn n: An integer
    # @return: An integer
    def numTrees(self, n):
        # write your code here
        dp = [1 for i in range(n+1)]
        for i in range(2, n+1):
            tmp = 0
            for j in range(1, i+1):
                tmp += dp[j-1] * dp[i-j]
            dp[i] = tmp

        return dp[n]
    原文作者:二叉查找树
    原文地址: https://blog.csdn.net/u012225151/article/details/52455258
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞