algorithm

package
v0.0.0-...-82289f8 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2020 License: MIT Imports: 2 Imported by: 0

README

翻转二叉树 easy

翻转一棵二叉树。

示例:

  输入:
  
       4
     /   \
    2     7
   / \   / \
  1   3 6   9
  输出:
  
       4
     /   \
    7     2
   / \   / \
  9   6 3   1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NULL = -1 << 63

NULL 方便添加测试数据

Functions

func Tree2Inorder

func Tree2Inorder(root *TreeNode) []int

Tree2Inorder 把 二叉树转换成 inorder 的切片

func Tree2Postorder

func Tree2Postorder(root *TreeNode) []int

Tree2Postorder 把 二叉树 转换成 postorder 的切片

func Tree2Preorder

func Tree2Preorder(root *TreeNode) []int

Tree2Preorder 把 二叉树 转换成 preorder 的切片

func Tree2ints

func Tree2ints(tn *TreeNode) []int

Tree2ints 把 *TreeNode 按照行还原成 []int

Types

type TreeNode

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

func GetTargetNode

func GetTargetNode(root *TreeNode, target int) *TreeNode

GetTargetNode 返回 Val = target 的 TreeNode root 中一定有 node.Val = target

func InPost2Tree

func InPost2Tree(in, post []int) *TreeNode

InPost2Tree 把 inorder 和 postorder 切片转换成 二叉树

func Ints2TreeNode

func Ints2TreeNode(ints []int) *TreeNode

Ints2TreeNode 利用 []int 生成 *TreeNode

func PreIn2Tree

func PreIn2Tree(pre, in []int) *TreeNode

PreIn2Tree 把 preorder 和 inorder 切片转换成 二叉树

func (*TreeNode) Equal

func (tn *TreeNode) Equal(a *TreeNode) bool

Equal return ture if tn == a

Jump to

Keyboard shortcuts

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