lc101

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

101.对称二叉树

1. 题目描述

给你一个二叉树的根节点 root , 检查它是否轴对称。

示例 1:


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

示例 2:


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

提示:

  • 树中节点数目在范围 [1, 1000]
  • -100 <= Node.val <= 100

进阶: 你可以运用递归和迭代两种方法解决这个问题吗?

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

2. 解题

采用递归的方法

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Balancer

type Balancer interface {
	// contains filtered or unexported methods
}

type Measurer

type Measurer interface {
	// contains filtered or unexported methods
}

type TreeNode

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

func BuildTree

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

BuildTree 根据前序遍历序列和中序遍历序列构造一个树,遍历序列中不可含有重复值

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