我的思路比较low直接看官方题解吧。。。
1 class Solution: 2 def numTrees(self, n: int) -> int: 3 G = [0] * (n+1) 4 G[0],G[1]=1,1 5 for i in range(2,n+1): 6 for j in range(1,i+1): 7 G[i] += G[j-1]*G[i-j] 8 return G[n]