代码如下:
class Solution(object):
def numTrees(self, n):
"""
:type n: int
:rtype: int
"""
dp = [1,1,2]
if n <= 2:
return dp[n]
dp += [0 for i in range(n-2)]
for i in range(3, n+1):
for j in range(i):
dp[i] += dp[j] * dp[i-j-1]
return dp[n]
网友评论