// 7 star, 多次未能解决,因此给七星,重点关注 funcgenerateTrees(n int) []*TreeNode { if n == 0 {return []*TreeNode{}} ret := dfs(1, n) return ret
}
funcdfs(start, end int) []*TreeNode { if start > end {return []*TreeNode{nil}} ret := []*TreeNode{} for mid:=start; mid<end+1; mid++ { left := dfs(start, mid-1) right := dfs(mid+1, end)
for _, l := range left { for _, r := range right { root := TreeNode{mid, nil, nil} root.Left, root.Right = l, r ret = append(ret, &root) } }