Skip to content

Latest commit

 

History

History
17 lines (15 loc) · 371 Bytes

File metadata and controls

17 lines (15 loc) · 371 Bytes
class Solution(object):
    def numTrees(self, n):
        """
        :type n: int
        :rtype: int
        """
        ans = [0 for i in range(n+1)]
        ans[0] = 1
        for op in range(1, n+1):
            for i in range(op):
                ans[op] += ans[i]*ans[op-1-i]
            
        return ans[-1]

记忆化搜索、递归、二叉树