leetcode 110.Balanced Binary Tree

来源:互联网 发布:好的诗句 知乎 编辑:程序博客网 时间:2024/06/06 20:01
题目:

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:






0 0
原创粉丝点击