class Solution(object):
def isBalanced(self, root):
"""
:type root: TreeNode
:rtype: bool
"""
if not root:
return True
left = self.getHight(root.left)
right = self.getHight(root.right)
return abs(left-right) <= 1 and self.isBalanced(root.left) and self.isBalanced(root.right)
def getHight(self,node):
if not node:
return 0
return max(self.getHight(node.left),self.getHight(node.right))+1