平衡二叉树

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
        

 

posted @ 2019-01-03 11:06  findtruth123  阅读(83)  评论(0编辑  收藏  举报