My Python solution using mathematical formula

  • 0

    The total number of BSTs is described by the function: (2n)! / ((n+1)! n!)

    class Solution(object):
        def numTrees(self, n):
            :type n: int
            :rtype: int
            return factorial(2 * n) / (factorial(n+1) * factorial(n))
    def factorial(n):
        return 1 if n == 0 else n * factorial(n-1)

Log in to reply

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