LeetCode-1161. Maximum Level Sum of a Binary Tree

箱线图原理与Python实战:从数据分布到异常值检测 在数据分析领域,理解数据分布特征是进行有效探索和决策的基础。数据分布描述了数据点的集中趋势、离散程度和形态,是统计分析的核心概念。其原理在于通过统计量(如中位数、四分位数)量化数据的内部结构,从而揭示潜在的模式和异常。掌握数据分布分析的技术价值在于,它能高效识别数据质量、发现业务洞察,并支撑稳健的模型构建。这一技术广泛应用于数据清洗、异常值检测和多组对比等场景,例如在金融风控、运营分析和产品评估中快速定位问题。箱线图正是实现这一过程的经典可视化工具,它通过五数概括法(最小值、下四分位数、中位数、上四分位数、 阅读详情

LeetCode-1161. Maximum Level Sum of a Binary Tree

  • 原题链接:https://leetcode.com/problems/maximum-level-sum-of-a-binary-tree/

解题思路

  • 其实就是二叉树的层次遍历的变种而已,二叉树层次遍历应该都很熟悉了,就不多说了

算法描述

  • Step1:如果根节点root为空,返回0
  • Step2:如果不为空,把root放入队列了,初始化最大值为root的数据值,数据和最大的层数初始化为1
  • Step3:然后按照二叉树层次遍历,计算每层数据和,和记录的最大值作比较,如果比已记录的最大值还要大,就更新最大值和最大值所在的层数
  • Step4:最后返回最大值所在层数

代码实现-Java

class Solution {
    public int maxLevelSum(TreeNode root) {
        if (root == null) {
            return 0;
        }
        Queue<TreeNode> queue = new LinkedList<>();
        queue.offer(root);
        int maxLevel=1, curLevel = 0;
        int max = root.val;
        int sum = 0;
        while(!queue.isEmpty()){
            int size = queue.size();
            curLevel++;
            sum = 0;
            for(int i=0;i<size;i++){
                TreeNode tmp = queue.poll();
                sum += tmp.val;
                if(tmp.left != null){
                    queue.offer(tmp.left);
                }
                if(tmp.right != null){
                    queue.offer(tmp.right);
                }
            }
            if(sum > max){
                max = sum;
                maxLevel = curLevel;
            }
        }
        return maxLevel;
    }
}

运行结果数据

Runtime: 9 ms, faster than 80.47% of Java online submissions for Maximum Level Sum of a Binary Tree. Memory Usage: 39.6 MB, less than 100.00% of Java online submissions for Maximum Level Sum of a Binary Tree.

YOLOv8环境搭建+训练自己的数据详细项目 直接按照路径会有问题,找到自己 requirements.txt 文件路径,我这里是pip install -r D:\ultralytics-main\ultralytics-main\requirements.txt。首先去自己的anaconda的安装的envs(虚拟环境),在导航栏输入cmd,进入命令窗口。到官方网站下载yolo模型 ,下载好后解压,里面有个文件requirements.txt。然后安装ultralytics ,这是必须的。 阅读详情

相关推荐

vscode+latex+bib文献管理

下载vscode 安装插件`` 在setting.json中配置 在.tex文件中编写论文内容,然后左侧TEX侧边栏中编译,如下图所示,中文用xelatex,英文用pdflatex;编译成功后,就可以查看pdf版本的论文了,我一般在浏览器显示。 涉及到文献编译:XXX.bib中存储文献管理内容;XXX.tex是文章内容,使用xelatex编译后会生成XXX.aux,ctrl+⋅ctrl+·ctrl+⋅打开命令行窗口,输入bibtex XXX(可以对aux文件进行编译,不需要加后缀),然后再xelatex.

小卜妞的博客 2552

LeetCode每日一题——1161. 最大层内元素和

本题是对dfs的简单应用。

MaTF_的博客 236

使用QGIS提取天地图遥感影像中的建筑物轮廓,及AI方案

用QGIS的插件提取遥感影像中的建筑轮廓,并提供了几个AI提取建筑轮廓的方案。

cky_123的博客 2万+

LeetCode 1161. Maximum Level Sum of a Binary Tree解题报告

1161. Maximum Level Sum of a Binary Tree Maximum Level Sum of a Binary Tree python solution 题目描述 Given the root of a binary tree, the level of its root is 1, the level of its children is 2, and so o...

Orientliu96的博客 270

机械臂速成小指南(八):标准DH法实战——从连杆坐标系到运动学方程

本文详细介绍了机械臂运动学建模中的标准DH法,从连杆坐标系的建立到运动学方程的求解,提供了实用的操作步骤和代码示例。通过DH参数表和变换矩阵的构建,帮助读者快速掌握机械臂运动学建模的核心技术,并解决实际应用中的常见问题。

oo7890的博客 217

零基础入门篇③ PyCharm使用指南(个性化设置、开发必备插件、常用快捷键)

Python从入门到精通👉零基础入门篇③

hacker707的博客 4387

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的博客 312

YOLOv8_obb训练流程-原理解析[旋转目标检测理论篇]

本文主要介绍了YOLOv8旋转目标检测的流程,介绍了标签的解码、预测结果的解码,以及如何理解旋转角度等内容,还介绍旋转目标检测框的正样本选取及Loss计算。

ice 4741

【Leetcode】2737. Find the Closest Marked Node

出发跑一遍Dijkstra即可。出发到达任一有标记的点的最短路。,图中若干点有标记,问从。阶带权有向图,点编号从。

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

【Burp入门第三十三篇】BurpSuite+Proxifier安装配置,实现微信小程序抓包

本文介绍Burp+Proxifier安装配置,实现微信小程序抓包

等风来 5882

微信小程序 - 解决web-view嵌套H5网页白屏问题,将h5网页嵌套在webview页面出现无法加载一片空白,详解微信小程序<web-view>页面跳转出现白屏情况(无论本地还是线上H5都能解决)

微信小程序解决web-view打开网页在手机上出现白屏的问题,小程序web-view嵌套H5项目白屏问题分析及解决,使用web-view组件加载H5网页链接后白屏情况,小程序嵌套的h5网页中跳转页面时也有可能出现白屏问题,嵌套webview页面时,出现白屏,WebView 加载不出网页,微信小程序<web-view>页面跳转出现白屏解决方法,解决WebView白屏空白,H5内嵌第三方小程序打开白屏,微信小程序嵌入h5页面加载空白,微信小程序web-view跳转h5白屏,解决微信小程序web-view打开网页

🏆 前端领域优质创作者 1万+

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的博客 266

Python数据可视化 Pyecharts 制作 Map 地图

大家好,我是Mr数据杨。想象一下,作为一名军师,如诸葛亮或郭嘉,'Map’就如同那战争的沙盘,兵马行动的轨迹,都需要准确的地图作为基础。‘基本设置’,就如同摆设这张战争沙盘,规定棋子的起始位置。‘数据配置选项’和’地图数据项’,就好比是军师们手中的情报,了解各路诸侯的兵力、粮草、地形等重要信息,以便于他们更好地布局。‘Demo’则代表着练兵之地,军师们可以在此基于已有数据,试验各种战术。

Mr数据杨 4万+

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

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

Made in Code 1075

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

[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

全球国家地区城市数据

MySQL全球国家地区城市数据报。。。。。。。。。。。。

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

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

邹九的个人博客 56

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

【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

suppose the level of root is 1. now we need to return the smallest level x that sum of all that node values of that level is the max. of course we can do that using level order traverse and maintain the smallest level and return it. but it not sounds like

Tech in Pieces 292

【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...

负雪明烛 1147

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的博客 605

leetcode - 1161. Maximum Level Sum of a Binary Tree

leetcode - 1161

sinat_41679123的博客 1082

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

LeetCode1161. Maximum Level Sum of a Binary Tree

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

叶卡捷琳堡的博客 207

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的博客 196

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

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的博客 164
上一篇: LeetCode-894. All Possible Full Binary Trees
下一篇: LeetCode-1104. Path In Zigzag Labelled Binary Tree
ke1950523491
博客等级 码龄10年 29粉丝 34原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值