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);
```