LeetCode--096--不同的二叉搜索树(python)

我的思路比较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]

猜你喜欢

转载自www.cnblogs.com/NPC-assange/p/11487044.html