# [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 every node never differ by more than 1.

## AC代码

public class BalancedBinaryTree {
static class TreeNode {
public int val;
public TreeNode left;
public TreeNode right;

public TreeNode(int x) {
this.val = x;
}
}

public static boolean isBalanced(TreeNode root) {
if (root == null) return true;

int lh = getHeight(root.left);
int rh = getHeight(root.right);

if (Math.abs(lh - rh) > 1) return false;

return isBalanced(root.left) && isBalanced(root.right);
}

public static int getHeight(TreeNode root) {
if (root == null) return 0;

return Math.max(getHeight(root.left), getHeight(root.right)) + 1;

}
}


## 吐槽

csdn神马时候才能支持markdown语法编辑博客啊，如果到过年还不支持markdown，果断迁移到segmentfault上了

• 本文已收录于以下专栏：

## 【LeetCode】Balanced Binary Tree 解题报告

【题目】 Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced bi...

## LeetCode(114) Flatten Binary Tree to Linked List解题报告

Given a binary tree, flatten it to a linked list in-place.For example, Given 1 / \ ...

## 【LeetCode】257. Binary Tree Paths 解题报告

举报原因： 您举报文章：深度学习：神经网络中的前向传播和反向传播算法推导 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)