#!/usr/bin/env python3

__author__ = 'Wei Mu'

class Solution:
    def numTrees(self, n: int) -> int:
        ans = [0] * (1+n)
        
        ans[0] = 1
        ans[1] = 1
        
        for i in range(2,n + 1):
            for j in range(i):
                ans[i] += ans[j] * ans[i - j - 1]
                
        
        return ans[n]
