class Solution: def treeHeight(self,root): if root==None: return 0 if root.left==None and root.right==None: return 1 lh=self.treeHeight(root.left) rh=self.treeHeight(root.right) return max(lh,rh)+1 def balanceTree(self,root): if root==None: return True lh=self.treeHeight(root.left) rh=self.treeHeight(root.right) return True if abs(lh-rh) <=1 else False