题目:
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 ofevery node never differ by more than 1.
要求判断一棵二叉树是否是平衡二叉树,即每个节点的左右子树高度差不超过1。
思路:采用递归的方式,分别判断左右子树是否是平衡树,再计算左右两棵子树的高度差是否超过1。
代码AC: