题目描述
输入一棵二叉树,判断该二叉树是否是平衡二叉树。
class Solution:
def IsBalanced_Solution(self, pRoot):
# write code here
if not pRoot:
return True
if abs(self.maxDepth(pRoot.left)-self.maxDepth(pRoot.right))>1:
return False
return self.IsBalanced_Solution(pRoot.left) and self.IsBalanced_Solution(pRoot.right)
def maxDepth(self, pRoot):
if not pRoot :
return 0
return max(self.maxDepth(pRoot.left), self.maxDepth(pRoot.right)) + 1