One line Python solution (formula)


  • 0
    S

    After feeling special for creating my own special formula, I realized someone smarter than me already did. It involves Catalan numbers in combinational mathematics.
    I strongly recommend reading up and learning about why this works.
    Other answers give great detailed explanations,
    but I posted this here in case you wanted to see a one-liner solution.

    class Solution(object):
        def numTrees(self, n):
            return (math.factorial(2 * n) / (math.factorial(n)**2)) / (n + 1);
    

Log in to reply
 

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