思路见这篇博客
class Solution:
# @paramn n: An integer
# @return: An integer
def numTrees(self, n):
# write your code here
dp = [1 for i in range(n+1)]
for i in range(2, n+1):
tmp = 0
for j in range(1, i+1):
tmp += dp[j-1] * dp[i-j]
dp[i] = tmp
return dp[n]