leetcode 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 of the two subtrees ofevery node never differ by more than 1.

要求判斷一棵二叉樹是否是平衡二叉樹,即每個節點的左右子樹高度差不超過1。


思路:採用遞歸的方式,分別判斷左右子樹是否是平衡樹,再計算左右兩棵子樹的高度差是否超過1。


代碼AC:






發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章