LeetCode(96)Unique Binary Search Trees

题目如下:

Python代码:

    def numTrees(self, n):
        """
        :type n: int
        :rtype: int
        """
        num=[0]*(n+1)
        num[0]=num[1]=1
        for i in range(2,n+1):
            for j in range(i):
                num[i] += num[j]*num[i-j-1]
        return num[n]

 

posted @ 2017-07-18 16:22  Single、Dog  阅读(146)  评论(0编辑  收藏  举报