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
相关推荐
2603_965148111 天前
如何解析JSON数据?API返回的商品信息处理教程
开发语言·数据库·python·自动化·json·api
fqq31 天前
力扣刷题前置Java语法
算法·leetcode·职场和发展
jufeng13071 天前
【系列:手搓自主 AI Agent:Hermes 架构原理剖析 · 第 8 篇】
python·ai agent·配置系统
circuitsosk1 天前
跨境电商智能化实战:AI如何赋能客服自动回复、广告智能投放与供应链预测
大数据·人工智能·python·langchain·智能客服
2601_956319881 天前
2026年零基础学量化:从看懂示例到写清条件和动作
人工智能·python
过期的秋刀鱼!1 天前
LangChain-D1-模型的工作流程
人工智能·python·langchain
半夏微凉半夏殇1 天前
x11与weston对比,优先选哪个
leetcode·均值算法·eclipse
萤火工厂目视化设计1 天前
智能制造与企业文化目视化浪潮下:中小工厂的机遇与挑战
python·制造
DeepVisionary1 天前
从GPT-5.6 Sol的Ultrafast模式看推理速度竞赛:750 token/秒背后,Cerebras的晶圆级生意
python·自动化
leisoo80971 天前
财报数据怎么排雷本地化Python构建财务异常预警系统
人工智能·python·算法