_tree

package
v0.0.0-...-10bc058 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2021 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsSymmetricV1

func IsSymmetricV1(root *TreeNode) bool

始化时我们把根节点入队两次。每次提取两个结点并比较它们的值 (队列中每两个连续的结点应该是相等的,而且它们的子树互为镜像) 然后将两个结点的左右子结点按相反的顺序插入队列中。

func IsSymmetricV2

func IsSymmetricV2(root *TreeNode) bool

通过「同步移动」两个指针的方法来遍历这棵树,p 指针和 q 指针一开始都指向这棵树的根 随后 p 右移时,q 左移,p 左移时,q 右移 每次检查当前 p 和 q 节点的值是否相等,如果相等再判断左右子树是否对称。

func IsValidBSTV1

func IsValidBSTV1(root *TreeNode) bool

循环遍历

func IsValidBSTV2

func IsValidBSTV2(root *TreeNode) bool

迭代遍历

func ZigzagLevelOrder

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

Types

type BSTIterator

type BSTIterator struct {
	Vals []int
	Last bool
}

func Constructor

func Constructor(root *TreeNode) BSTIterator

二叉搜索树迭代器, 最简单的就是构造一个中序遍历

func (*BSTIterator) HasNext

func (this *BSTIterator) HasNext() bool

func (*BSTIterator) Next

func (this *BSTIterator) Next() int

type Codec

type Codec struct {
}

func ConstructorV2

func ConstructorV2() Codec

type Node

type Node struct {
	Val   int
	Left  *Node
	Right *Node
	Next  *Node
}

type TreeNode

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

func GetNode

func GetNode(str string) *TreeNode

Jump to

Keyboard shortcuts

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