zoukankan      html  css  js  c++  java
  • 110.Balanced Binary Tree

    # Definition for a binary tree node.
    # class TreeNode:
    #     def __init__(self, val=0, left=None, right=None):
    #         self.val = val
    #         self.left = left
    #         self.right = right
    class Solution:
        def isBalanced(self, root: TreeNode) -> bool:
            if root == None:
                return True
            l_depth, r_depth = 0 , 0
            if root.left != None:
                l_depth = self.subtreeHight(root.left)
            if root.right != None:
                r_depth = self.subtreeHight(root.right)
            if abs(l_depth - r_depth) > 1:
                return False
            else:
                return self.isBalanced(root.left) and self.isBalanced(root.right)
            
        def subtreeHight(self, root):
            if root == None:
                return 0
            return max(self.subtreeHight(root.left), self.subtreeHight(root.right)) + 1
  • 相关阅读:
    第十六周个人作业
    排球比赛积分程序
    本周个人总结
    本周个人总结
    排球积分规则
    我与计算机
    排球计分(实践)
    观后感
    18周 个人作业
    总结
  • 原文地址:https://www.cnblogs.com/luo-c/p/12857314.html
Copyright © 2011-2022 走看看