题目链接
题目描述
输入一棵二叉树,判断该二叉树是否是平衡二叉树。
solution
class Solution:
def TreeDepth(self,pRoot):
if pRoot == None:
return True
return max(self.TreeDepth(pRoot.left) + 1,self.TreeDepth(pRoot.right) + 1)
def IsBalanced_Solution(self, pRoot):
if pRoot == None:
return True
left = self.TreeDepth(pRoot.left)
right = self.TreeDepth(pRoot.right)
if abs(left -right)<=1:
return True