Skip to content

Latest commit

 

History

History

12-height-balanced

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

平衡二叉树 Height Balanced

高度平衡二叉树定义为:一个二叉树每个节点*的左右两个子树的高度差的绝对值不超过 1 。

Height-balanced binary tree is defined as: a binary tree in which the left and right subtrees of every node differ in height by no more than 1.

Problem

判断二叉树是否是高度平衡的二叉树。

Given a binary tree, determine if it is height-balanced.

Example:

Input:root = [3,9,20,null,null,15,7]
Output:true

Example:

Input: root = [1,2,2,3,3,null,null,4,4]
Output: false

Example:

Input: root = []
Output: true

Solution

编号 解法 Approach
1 递归 Recursion
2 迭代 Iteration

1. 递归 Recursion

图解流程

[暂无]

代码示例

recursion.js

复杂度分析

时间复杂度 空间复杂度
O(n) O(n)

2. 迭代 Iteration

图解流程

[暂无]

代码示例

iteration.js

复杂度分析

时间复杂度 空间复杂度
O(n) O(n)