-- coding:utf-8 --
class TreeNode:
def init(self, x):
self.val = x
self.left = None
self.right = None
class Solution:
def IsBalanced_Solution(self, pRoot):
# write code here
# 从根节点开始求树深
if pRoot is None:return True
left=self.get_deepth(pRoot.left)
right=self.get_deepth(pRoot.right)
if abs(left-right)<2:return self.IsBalanced_Solution(pRoot.left)and self.IsBalanced_Solution(pRoot.right)
else:return False
#求树深
def get_deepth(self,pRoot):
if pRoot is None:return 0
left=self.get_deepth(pRoot.left)
right=self.get_deepth(pRoot.right)
return max(left,right)+1