yysue

## Question

110. Balanced Binary Tree

## Solution

Java实现：

``````public boolean isBalanced(TreeNode root) {
boolean[] balanced = {true};
height(root, balanced);
return balanced[0];
}

private int height(TreeNode node, boolean[] balanced) {
if (node == null) return 0;
int leftHeight = height(node.left, balanced);
int rightHeight = height(node.right, balanced);
balanced[0] = balanced[0] && !(Math.abs(leftHeight - rightHeight) > 1);
return balanced[0] ? Math.max(leftHeight, rightHeight) + 1 : -1;
}
``````

## Ref

https://www.youtube.com/watch?v=C75oWiy0bWM

© 著作权归作者所有

### yysue

leetCode 110. Balanced Binary Tree 平衡二叉树

110. Balanced Binary Tree Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary tree is defined as a binary tree in which the depth......

wbf961127
2017/11/13
0
0
Leetcode 110. Balanced Binary Tree

SnailTyan
2018/09/19
0
0
leetcode -- Balanced Binary Tree

Balanced Binary Tree Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of t......

leiline
2018/01/12
0
0
[LeetCode] Balanced Binary Tree 平衡二叉树

Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of ev......

2017/12/11
0
0
LeetCode 攻略 - 2019 年 6 月汇总

Create by jsliang on 2019-06-28 09:03:23 Recently revised in 2019-06-28 14:56:36 一 目录 不折腾的前端，和咸鱼有什么区别 目录 一 目录 二 前言 三 汇总  3.1 已攻略  3.2 Function ...

jsliang
06/28
0
0

3
0
rest 的理解

rest：表现层状态转移。 什么是restful协议？https://en.wikipedia.org/wiki/Representational_state_transfer 使用restful的好处。 Rest是一种体系结构样式，他定义了一组用于创建web服务的...

xiaoxiao_go

5
0

go4it

4
0

5
0
Android Camera原理之CameraDeviceCallbacks回调模块

7
0