Given a binary tree, determine if it is height-balanced.
For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never differ by more than 1.
# Definition for a binary tree node.# class TreeNode(object):# def __init__(self, x):# self.val = x# self.left = None# self.right = NoneclassSolution(object):# should have two return value <balanced, height># judge start from the bottom defvalid(self,node):ifnode==None:returnTrue,0balanced,lh=self.valid(node.left)ifbalanced==False:returnFalse,0balanced,rh=self.valid(node.right)ifbalanced==False:returnFalse,0returnabs(lh-rh)<=1,max(lh,rh)+1defisBalanced(self,root):""" :type root: TreeNode :rtype: bool """balanced,height=self.valid(root)returnbalanced