Concise Python Code


  • 0
    C

    See below.

    `` ``` `

    def numTrees(self, n):
               
        if n == 0 or n == 1:
            return 1
        else:
            result = [0 for i in range(n+1)]
            result[0], result[1] = 1, 1
            for i in range(2, n+1):
                for k in range(1, i+1):
                    result[i] += result[k-1]*result[i-k]
            return result[n]
    

    `` ``` `


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.