# -*- coding:utf-8 -*-
# class TreeNode:
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None
class Solution:
def deep(self,pRoot):
if not pRoot:
return 0
L=self.deep(pRoot.left)
R=self.deep(pRoot.right)
return max(L,R)+1
def IsBalanced_Solution(self, pRoot):
# write code here
if not pRoot:
return True
L=self.deep(pRoot.left)
R=self.deep(pRoot.right)
if abs(L-R)>1:
return False
else:
return self.IsBalanced_Solution(pRoot.left) and self.IsBalanced_Solution(pRoot.right)