Python DP solution


  • 1
    G
    class Solution:
        # @return an integer]
        # 1:05
        def numTrees(self, n):
            count = [0] * (n + 1)
            count[0] = 1
    
            for i in range(1, n + 1):
                for j in range(0, i):
                    count[i] += count[j] * count[i - j - 1]
    
            return count[n]

Log in to reply
 

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