标签:bubuko @param 技术分享 turn 技术 img solution mtr src
给出 n,问由 1...n 为节点组成的不同的二叉查找树有多少种?
给出n = 3,有5种不同形态的二叉查找树:
class Solution:
"""
@param n: An integer
@return: An integer
"""
def numTrees(self, n):
# write your code here
ans = [0] * (n+1)
ans[0] = 1
for i in range(1, n+1):
for j in range(0, i):
ans[i] += ans[j]*ans[i-j-1]
return ans[n]
标签:bubuko @param 技术分享 turn 技术 img solution mtr src
原文地址:https://www.cnblogs.com/narjaja/p/9801071.html