leetcode 1161. Maximum Level Sum of a Binary Tree(二叉树最大层和)

避开这些坑!晶圆封装中Wire Bonding(引线键合)的5种常见不良与实战调试心得 本文深入探讨晶圆封装中Wire Bonding(引线键合)的5种常见不良现象,包括Wire Offset、BSOB不良、球径/球厚异常、弧度不良和IMC问题。通过实际案例和参数优化方案,帮助工程师提升封装质量和可靠性,特别适用于半导体封装领域的专业人士。 阅读详情

在这里插入图片描述

root所在层为1,后面依次加1.
每层求和,找到和最大的层数。

思路:

一层一层求和,想到BFS。
记录下最初的和为root.val.
后面的和超过这个值,就更新sum, 更新层数。

public int maxLevelSum(TreeNode root) {
    int level = 0;
    int maxLevel = 1;
    int sum = root.val;
    Queue<TreeNode> queue = new LinkedList<>();
    queue.offer(root);

    while(queue.size() > 0) {
        int size = queue.size();
        int tmp = 0;
        level ++;
        for(int i = 0; i < size; i++){
            TreeNode cur = queue.poll();
            tmp += cur.val;
            if(cur.left != null) queue.offer(cur.left);
            if(cur.right != null) queue.offer(cur.right);
        }
        
        if(tmp > sum) {
            sum = tmp;
            maxLevel = level;
        }
    }
    return maxLevel;
}
【Zephyr存储专题】06_存储块设备驱动开发(Nand Flash) 本文介绍了基于Zephyr系统的NAND Flash驱动实现方案,重点阐述了Flash驱动模型的核心架构和关键API设计。 阅读详情

相关推荐

雪莉果的Axure原型工厂vol.006 中继器应用(二)——多选穿梭框

如果你用axure有一段时间了,那么你很快就能琢磨出一个大体设计流程,比如加一个中间过度的元件,来储存需要穿梭的内容;但是如果你再想一想,就会发现,这样做,似乎只能解决单选,那么多选需要怎么操作呢? 这时候,中继器就会告诉你,我还能做的更多。

weixin_43829792的博客 976

leetcode 1161. Maximum Level Sum of a Binary Tree 最大层内元素和-耗时100

Problem:耗时100%,累加每一层的和,求出最大高度,得到最大值和对应的层数。

邹九的个人博客 55

告别手写代码!用Simulink给TI F28335 DSP自动生成C代码(保姆级环境配置)

本文详细介绍了如何利用Simulink为TI F28335 DSP自动生成C代码,告别传统手写代码的低效与错误。通过保姆级环境配置指南和实战案例,帮助开发者快速掌握模型驱动开发方法,大幅提升嵌入式开发效率,特别适合需要频繁修改算法参数或团队协作的工程师。

weixin_30388677的博客 416

LeetCode-1161. Maximum Level Sum of a Binary Tree

LeetCode-1161. Maximum Level Sum of a Binary Tree 原题链接:https://leetcode.com/problems/maximum-level-sum-of-a-binary-tree/ 解题思路 其实就是二叉树的层次遍历的变种而已,二叉树层次遍历应该都很熟悉了,就不多说了 算法描述 Step1:如果根节点root为空,返回0 Ste...

ke1950523491的博客 262

Xilinx PCIe IP核示例工程仿真流程与关键任务解析

本文详细解析了Xilinx PCIe IP核示例工程的仿真流程与关键任务。通过搭建仿真环境、解读初始化日志,并深入剖析TSK_TX_MEMORY_WRITE_32等核心任务的TLP报文生成与交互过程,帮助开发者掌握PCIe IP核的仿真调试方法,为实际硬件设计提供可靠的验证基础。

weixin_28314575的博客 504

避坑指南:Unity新版InputSystem在移动端的5个常见问题及解决方案

本文针对Unity新版InputSystem在移动端开发中的常见问题,提供了5个关键解决方案,包括虚拟摇杆灵敏度调节、多点触控冲突处理、按钮反馈延迟优化、手势识别与陀螺仪数据融合以及Android/iOS平台差异处理。这些实战经验帮助开发者高效解决触控适配难题,提升移动游戏体验。

soda5的博客 404

【LeetCode】1161. Maximum Level Sum of a Binary Tree 解题报告 (C++)

作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录题目描述题目大意解题方法BFS日期 题目地址:https://leetcode.com/problems/maximum-level-sum-of-a-binary-tree/ 题目描述 Given the root of a binary tree, the l...

负雪明烛 1145

YOLOv5基于深度学习的道路缺陷检测系统

然而,由于长期的自然侵蚀、车辆磨损等因素,道路表面容易出现裂缝、坑洼等缺陷。这些缺陷不仅会影响驾驶舒适性,还可能引发交通事故,尤其是在恶劣天气或夜间行车条件下。随着人工智能技术的快速发展,基于深度学习的道路缺陷检测技术能够在降低人力成本的同时提高检测效率,为道路维护提供了新的解决方案。本项目构建了基于YOLOv5的道路缺陷检测系统,结合PyQt5开发了用户友好的UI界面,具备实时检测和图片分析功能。工具对图片进行标注,生成YOLO格式的标注文件。上传包含道路裂缝或坑洼的图片,系统会标注出缺陷的位置及类别。

YOLO 1076

Leetcode 1161.最大层内元素和(Maximum Level Sum of a Binary Tree)

Leetcode 1161.最大层内元素和 1 题目描述(Leetcode题目链接)   给你一个二叉树的根节点 root。设根节点位于二叉树的第 1 层,而根节点的子节点位于第 2 层,依此类推。   请你找出层内元素之和 最大 的那几层(可能只有一层)的层号,并返回其中 最小 的那个。 输入:[1,7,0,7,-8,null,null] 输出:2 解释: 第 1 层各元素之和为 1, 第 2...

qq_39378221的博客 195

芒果YOLO11改进23:主干Backbone篇GhostNet:原创改进高效 GhostNet 网络,华为出品,打造全新检测器

主干Backbone篇GhostNet:原创改进高效 GhostNet 网络,华为出品,打造全新检测器

包括YOLOv5、YOLOv7、YOLOv8等模型改进 404

文末含资料链接和视频讲解!YOLOv8集成CoordAtt注意力机制详细教程

本文详细介绍了如何在YOLOv8目标检测框架中集成CoordAtt注意力机制。首先解析了CoordAtt的工作原理,它通过分解式池化将位置信息嵌入到通道注意力中,相比传统注意力机制具有更好的空间信息保持能力。然后提供了PyTorch实现代码解析,包括自适应平均池化、Hard-Swish激活函数等关键实现细节。最后概述了YOLOv8架构,为后续集成CoordAtt提供基础。该教程适合具备深度学习基础的开发者,将理论与实践结合,帮助读者掌握这一目标检测优化技术。

FJN110的博客 266

LeetCode //C - 1161. Maximum Level Sum of a Binary Tree

【代码】LeetCode //C - 1161. Maximum Level Sum of a Binary Tree。

Made in Code 1073

在 SAP S/4HANA Public Cloud 中做产品扩展:从 Key User 到 ABAP Cloud 与 BTP 的三轨实践指南

摘要:SAP S/4HANA Public Cloud 提供三种扩展方式(key user、developer extensibility 和 side-by-side),遵循 clean core 原则确保升级稳定。key user 扩展适合无代码轻量改良,developer extensibility 用于受控 ABAP 开发,side-by-side 则适用于云原生独立应用。文章通过销售订单优先级字段、退货审批微服务和采购校验等案例,说明不同扩展路径的适用场景与实现方法,帮助开发者在三系统景观中合理选

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 293

1161. Maximum Level Sum of a Binary Tree**

1161. Maximum Level Sum of a Binary Tree** https://leetcode.com/problems/maximum-level-sum-of-a-binary-tree/ 题目描述 Given the root of a binary tree, the level of its root is 1, the level of its children...

珍妮的选择的博客 384

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

1161. Maximum Level Sum of a Binary Tree

import java.util.* import kotlin.collections.HashMap /** * 1161. Maximum Level Sum of a Binary Tree * https://leetcode.com/problems/maximum-level-sum-of-a-binary-tree/description/ * *...

weixin_30664615的博客 247

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

[leetcode] 1161. Maximum Level Sum of a Binary Tree

Description Given the root of a binary tree, the level of its root is 1, the level of its children is 2, and so on. Return the smallest level X such that the sum of all the values of nodes at level X is maximal. Example 1: Input: root = [1,7,0,7,-8,null,nu

Learning from the mistakes 245

IMSL CNL 7.0.0 (x86-64)Crack

IMSL CNL 7.0.0 (x86-64)Crack intel的算法库破解文件,这是C++版本的破解文件

1161 Maximum Level Sum of a Binary Tree

1 题目 Given therootof a binary tree, the level of its root is1,the level of its children is2,and so on. Return thesmallestlevelXsuch that the sum of all the values of nodes at levelXisma...

weixin_39145266的博客 222

Leetcode 1161. Maximum Level Sum of a Binary Tree

题目链接:2. Add Two Numbers 题目大意:给你由两个链表组成得数,链表上得每个位置得值代表一个位得值,例如3->8->4就代表483这个值,然后两个链表相加,返回结果。 题目思路:简单题,每次相加得时候记录一次进位就可以了,只不过处理链表得时候比较麻烦,具体看代码吧 时间复杂度&&空间复杂度:O(max(n,m))&&O(n+m)(n,m...

Nemaleswang的博客 265

LeetCode解题分享:1161. Maximum Level Sum of a Binary Tree

Problem Given the root of a binary tree, the level of its root is 1, the level of its children is 2, and so on. Return the smallest level X such that the sum of all the values of nodes at level X is m...

DaVinciL的博客 603

LeetCode C++ 1161. Maximum Level Sum of a Binary Tree【Tree/BFS】中等

Given the root of a binary tree, the level of its root is 1, the level of its children is 2, and so on. Return the smallest level X such that the sum of all the values of nodes at level X is maximal. Example 1: Input: root = [1,7,0,7,-8,null,nul

memcpy0的博客 396

LeetCode 1161. Maximum Level Sum of a Binary Tree (Medium)

Description: Given the root of a binary tree, the level of its root is 1, the level of its children is 2, and so on. Return the smallest level X such that the sum of all the values of nodes at level ...

weixin_45744426的博客 310

LeetCode #1161 Maximum Level Sum of a Binary Tree 最大层内元素和

输入:root = [989,null,10250,98693,-89388,null,null,null,-32127]设根节点位于二叉树的第 1 层,而根节点的子节点位于第 2 层,依此类推。请返回层内元素之和 最大 的那几层(可能只有一层)的层号,并返回其中 最小 的那个。输入:root = [1,7,0,7,-8,null,null]所以我们返回第 2 层的层号,它的层内元素之和最大。第 3 层各元素之和为 7 + -8 = -1,记录每一层的和及对应层数输出最大的和的层的编号。

NSJ85的博客 163

【Leetcode】1161. Maximum Level Sum of a Binary Tree

题目地址: https://leetcode.com/problems/maximum-level-sum-of-a-binary-tree/ 给定一个二叉树,问其哪一层的节点数字和最大。若有多个解,则返回最小的那个。树根的层数规定为111。 直接用层序遍历即可。代码如下: import java.util.LinkedList; import java.util.Queue; public class Solution { public int maxLevelSum(TreeNode root

数学、算法爱好者的博客 254

leetcode - 1161. Maximum Level Sum of a Binary Tree

leetcode - 1161

sinat_41679123的博客 1081

LeetCode - Medium - 1161. Maximum Level Sum of a Binary Tree

Topic Tree Breadth-First Search Description https://leetcode.com/problems/maximum-level-sum-of-a-binary-tree/ Given the root of a binary tree, the level of its root is 1, the level of its children is 2, and so on. Return the smallest level x such that th

KISS 252

LeetCode1161. Maximum Level Sum of a Binary Tree

【代码】LeetCode1161. Maximum Level Sum of a Binary Tree。

叶卡捷琳堡的博客 206
上一篇: leetcode 2352. Equal Row and Column Pairs(相等的行和列)
下一篇: torchvision.ops.nms实现NMS
蓝羽飞鸟
博客等级 码龄8年 1万+粉丝 727原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

蓝羽飞鸟

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值