高度平衡二叉树定义为:一个二叉树每个节点*的左右两个子树的高度差的绝对值不超过 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.
判断二叉树是否是高度平衡的二叉树。
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
编号 | 解法 | Approach |
---|---|---|
1 | 递归 | Recursion |
2 | 迭代 | Iteration |
[暂无]
recursion.js
时间复杂度 | 空间复杂度 |
---|---|
O(n) | O(n) |
[暂无]
iteration.js
时间复杂度 | 空间复杂度 |
---|---|
O(n) | O(n) |