LeetCode - 096-- different binary search tree (python)

My idea of ​​looking directly at the relatively low official explanations of it. . .

 

 

 

 

 

 

 

 

 

 

 

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]

 

Guess you like

Origin www.cnblogs.com/NPC-assange/p/11487044.html