-- coding:utf-8 --

class TreeNode:

def init(self, x):

self.val = x

self.left = None

self.right = None

class Solution:
def IsBalanced(self,pRoot):
if pRoot is None:
return True,0
else:
booll,depthl=self.IsBalanced(pRoot.left)
boolr,depthr=self.IsBalanced(pRoot.right)
if booll and boolr and abs(depthl-depthr)<=1:
return True,max(depthl,depthr)+1
else:
return False,max(depthl,depthr)+1
def IsBalanced_Solution(self,pRoot):
return self.IsBalanced(pRoot)[0]