110._balanced_binary_tree.md 724 字节
Newer Older
K
KEQI HUANG 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
###110. Balanced Binary Tree

题目:
<https://leetcode.com/problems/balanced-binary-tree/>


难度:
Easy


全程递归中



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