Python | Leetcode Python题解之第110题平衡二叉树

题目:

题解:

python 复制代码
class Solution:
    def isBalanced(self, root: TreeNode) -> bool:
        def height(root: TreeNode) -> int:
            if not root:
                return 0
            leftHeight = height(root.left)
            rightHeight = height(root.right)
            if leftHeight == -1 or rightHeight == -1 or abs(leftHeight - rightHeight) > 1:
                return -1
            else:
                return max(leftHeight, rightHeight) + 1

        return height(root) >= 0
相关推荐
子龙烜20 分钟前
数据分析三剑客-Matplotlib
python·数据挖掘·数据分析·matplotlib
图灵追慕者21 分钟前
python绘制领域矩形
开发语言·python·领域
Recitative36 分钟前
python单元测试入门
人工智能·python·深度学习·机器学习·单元测试
小安同学iter40 分钟前
计算机大方向的选择
python·django·pygame
wxin_VXbishe1 小时前
servlet职称评审系统-计算机毕业设计源码00122
java·spring boot·python·servlet·django·flask·php
捉鸭子1 小时前
蜜雪冰城小程序逆向
javascript·爬虫·python·网络爬虫·逆向
满心欢喜love2 小时前
Python爬虫康复训练——笔趣阁《神魂至尊》
开发语言·爬虫·python
山脚ice2 小时前
【CT】LeetCode手撕—704. 二分查找
算法·leetcode
阿福不是狗2 小时前
PyQt5之理解和使用Python中的qasync:连接Qt和asyncio的桥梁
数据库·python·qt
wxin_VXbishe2 小时前
springboot城市菜园共享系统-计算机毕业设计源码00524
java·hadoop·spring boot·python·spring·django·php