goden0409

package
v0.0.0-...-b071cee Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 9, 2023 License: GPL-3.0 Imports: 0 Imported by: 0

README

面试题 04.09.二叉搜索树序列

1. 题目描述

从左向右遍历一个数组,通过不断将其中的元素插入树中可以逐步地生成一棵二叉搜索树。

给定一个由 不同节点 组成的二叉搜索树 root ,输出所有可能生成此树的数组。

示例 1:


输入: root = [2,1,3]
输出: [[2,1,3],[2,3,1]]
解释: 数组 [2,1,3]、[2,3,1] 均可以通过从左向右遍历元素插入树中形成以下二叉搜索树
       2 
      / \ 
     1   3

示例 2:

输入: root = [4,1,null,null,3,2]
输出: [[4,1,3,2]]

提示:

  • 二叉搜索树中的节点数在 [0, 1000] 的范围内
  • 1 <= 节点值 <= 10^6
  • 用例保证符合要求的数组数量不超过 5000

标签 二叉搜索树 回溯 二叉树

2. 解题

TODO: 没搞懂

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BSTSequences

func BSTSequences(root *TreeNode) [][]int

*

  • Definition for a binary tree node.
  • type TreeNode struct {
  • Val int
  • Left *TreeNode
  • Right *TreeNode
  • }

Types

type TreeNode

type TreeNode struct {
	Val   int
	Left  *TreeNode
	Right *TreeNode
}

func BuildTree

func BuildTree(preorder []int, inorder []int) *TreeNode

func (*TreeNode) Find

func (root *TreeNode) Find(v int) *TreeNode

func (*TreeNode) InOrder

func (root *TreeNode) InOrder(Visit func(node *TreeNode))

func (*TreeNode) PostOrder

func (root *TreeNode) PostOrder(Visit func(node *TreeNode))

func (*TreeNode) PreOrder

func (root *TreeNode) PreOrder(Visit func(node *TreeNode))

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL