README ¶ 面试题 04.04.检查平衡性 1. 题目描述 实现一个函数,检查二叉树是否平衡。在这个问题中,平衡树的定义如下:任意一个节点,其两棵子树的高度差不超过 1。 示例 1: 给定二叉树 [3,9,20,null,null,15,7] 3 / \ 9 20 / \ 15 7 返回 true 。 示例 2: 给定二叉树 [1,2,2,3,3,null,null,4,4] 1 / \ 2 2 / \ 3 3 / \ 4 4 返回 false 。 标签 树 深度优先搜索 二叉树 2. 解题 Expand ▾ Collapse ▴ Documentation ¶ Index ¶ type TreeNode func BuildTree(preorder []int, inorder []int) *TreeNode func (root *TreeNode) InOrder(Visit func(val int)) func (root *TreeNode) PostOrder(Visit func(val int)) func (root *TreeNode) PreOrder(Visit func(val int)) 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) InOrder ¶ func (root *TreeNode) InOrder(Visit func(val int)) func (*TreeNode) PostOrder ¶ func (root *TreeNode) PostOrder(Visit func(val int)) func (*TreeNode) PreOrder ¶ func (root *TreeNode) PreOrder(Visit func(val int)) Source Files ¶ View all Source files Tree.gogoden0404.go Click to show internal directories. Click to hide internal directories.