# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
class Solution:
def generateTrees(self, n: int) -> List[Optional[TreeNode]]:
def buildtree(start,end):
if start > end:
return [None]
alltrees = []
for i in range(start,end+1):
left = buildtree(start,i-1)
right = buildtree(i+1,end)
for left_tree in left:
for right_tree in right:
root = TreeNode(i)
root.left = left_tree
root.right = right_tree
alltrees.append(root)
return alltrees
return buildtree(1,n)
标签:right,end,Python,self,tree,二叉,start,搜索,left
From: https://www.cnblogs.com/DCFV/p/18457747