goden0406

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.06.后继者

1. 题目描述

设计一个算法,找出二叉搜索树中指定节点的“下一个”节点(也即中序后继)。

如果指定节点没有对应的“下一个”节点,则返回 null

示例 1:

输入: root = [2,1,3], p = 1

  2
 / \
1   3

输出: 2

示例 2:

输入: root = [5,3,6,2,4,null,null,1], p = 6

      5
     / \
    3   6
   / \
  2   4
 /   
1

输出: null

标签 深度优先搜索 二叉搜索树 二叉树

2. 解题

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

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(val int))

func (*TreeNode) PreOrder

func (root *TreeNode) PreOrder(Visit func(val int))

Jump to

Keyboard shortcuts

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