leetcode 637. Average of Levels in Binary Tree(二叉树每层的平均数)

Win11注册表没有MMC的解决方法 本文详细介绍了在Win11系统中解决注册表没有MMC项的问题的方法。通过创建并导入注册表修复文件,我们可以成功地在注册表中添加缺失的MMC项。在操作过程中,需要注意备份注册表、以管理员身份运行工具以及系统更新等事项。希望本文能够帮助到遇到类似问题的用户,提高系统管理的效率和便捷性。如果你还有其他关于Windows操作系统的问题或疑问,欢迎随时提问并寻求帮助。 阅读详情

Given a non-empty binary tree, return the average value of the nodes on each level in the form of an array.
Example 1:

Input:
    3
   / \
  9  20
    /  \
   15   7

Output: [3, 14.5, 11]
Explanation:
The average value of nodes on level 0 is 3, on level 1 is 14.5, and on level 2 is 11. Hence return [3, 14.5, 11].
Note:
The range of node’s value is in the range of 32-bit signed integer.

计算二叉树每层的平均值,返回list

思路:
BFS,对每层节点值求和再求平均
注意和要用long类型,用int类型在相加的时候可能会溢出,保存时cast到double。或者直接用double型

public List<Double> averageOfLevels(TreeNode root) {
    Queue<TreeNode> queue = new LinkedList<>();
    List<Double> res = new ArrayList<>();
    queue.offer(root);
    
    while(!queue.isEmpty()) {
        double val = 0.0;
        int size = queue.size();
        for(int i = 0; i < size; i++) {
            TreeNode cur = queue.poll();
            val += cur.val;
            if(cur.left != null) queue.offer(cur.left);
            if(cur.right != null) queue.offer(cur.right);
        }
        res.add(val/size);
    }
    return res;
}
hwasan实例分析踩内存之一:camx进程stack tag-mismatch的三种解决方案 hwasan实例分析踩内存之一:camx进程stack tag-mismatch的三种解决方案。 阅读详情

相关推荐

别再手动连线了!用Tessent IJTAG的SIB和TDR,5分钟搞定复杂芯片的DFT网络分区

本文探讨了如何利用Tessent IJTAG的SIB(Segment Insertion Bit)和TDR(Test Data Register)技术,高效解决复杂芯片DFT网络分区问题。通过智能化的扫描链管理和声明式定义,显著降低连接复杂度,提升测试覆盖率和良率,适用于超大规模SoC设计。

weixin_29251131的博客 313

leetcode 637. Average of Levels in Binary Tree二叉树的每层平均数

leetcode 637. Average of Levels in Binary Tree二叉树的每层平均数

Shauna_Wu的博客 419

交流异步机VVVF变频控制simulink/matlab仿真分析

VVVF,是Variable Voltage and Variable Frequency的缩写, 意为:可变电压、可变频率,也就是变频调速系统。 VVVF控制的逆变器连接电机,通过同时改变频率和电压,达到磁通恒定(可以用反电势/频率近似表征)和控制电机转速(和频率成正比)的目的,所以多应用在变频器中,属于工业自动化领域。

Ezekiel_Mok的博客 4235

leetcode 637. Average of Levels in Binary Tree

Given a non-empty binary tree, return the average value of the nodes on each level in the form of an array. Example 1: Input: 3 / \ 9 20 / \ 15 7 Output: [3, 14.5, 11] Explan

淡然坊 2296

从CPRI到eCPRI:手把手教你用Wireshark分析基站前传协议帧结构

本文手把手教你使用Wireshark工具,深入解析从CPRI到eCPRI的基站前传协议帧结构。通过搭建分析环境、编写解析脚本,并对比两者在时延管理、帧格式及数据封装上的差异,为无线通信领域的研发与测试人员提供了一套实用的逆向分析与故障排查方法。

x8y9z0的博客 611

一些笔者原创或者搜集的 ABAP 小工具集合(一),持续更新中!!

每个报表短小精悍,拷贝到系统激活即可运行。不少报表脑洞大开。

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

[leetcode]637. Average of Levels in Binary Tree(Python)

[leetcode]637. Average of Levels in Binary Tree题目描述题目理解解题思路DFSBFSMyMethodTime 题目描述 Category:Easy Tree Given a non-empty binary tree, return the average value of the nodes on each level in the form of...

La_Ragazza的博客 485

wireshark提取视频数据之RTP包中提取H264和H265

本文主要描述从wireshark包数据中提取出H264和H265裸流数据方法,裸流通过RTP封包方式发送,从抓包中直接提取视频流数据,进而进行流媒体问题定位

技术控的笔记 17万+

[LeetCode] 637. Average of Levels in Binary Tree

原题链接: https://leetcode.com/problems/average-of-levels-in-binary-tree/ 1. 题目介绍 Given a non-empty binary tree, return the average value of the nodes on each level in the form of an array. 给出一个非空的二叉树,返回每...

Ber03的博客 272

uni-app - 修改默认端口,H5 项目控制台运行出来的 IP 地址的默认端口号(H5 项目运行后控制台,修改项目运行到内置浏览器默认 8080 端口号)

uni-app运行到H5修改默认端口号,uni-app如何修改默认端口,uni-app修改默认端口,uni-app本地运行修改调试已上线微信H5项目,请问在UNIAPP的H5运行调试时候的IP是否可以自己设置固定,uni-app开发环境,如何设置h5服务器的端口,uni-app如何修改默认端,uni-app修改默认端口,uni-app指定端口号,uni-app-修改H5项目控制台运行出来的IP地址的默认端口号(H5项目运行后控制台,修改项目运行到内置浏览器默认8080端口号)

🏆 前端领域优质创作者 9895

YOLOv11改进策略【卷积层】| arXiv 2025 YOLO-Master中的稀疏混合专家ES-MoE 动态路由提适配 + 稀疏激活降延迟,突破精度-效率权衡

ES-MoE(Efficient Sparse Mixture-of-Experts)是为解决传统YOLO类实时目标检测器的静态计算冗余问题而提出的稀疏混合专家模块。现有YOLO架构对所有输入场景采用统一的密集计算模式,导致简单场景资源浪费、复杂场景(如密集小目标、遮挡场景)计算不足,难以平衡检测精度与推理速度。ES-MoE引入实例条件自适应计算,通过动态路由机制为不同复杂度的输入分配差异化计算资源,突破传统静态架构的精度-效率权衡限制,同时适配实时检测的轻量化需求。

Limiiiing的博客 471

LeetCode 637. Average of Levels in Binary Tree(一棵树每层节点的平均数)

Given a non-empty binary tree, return the average value of the nodes on each level in the form of an array. Example 1: Input: 3 / \ 9 20 / \ 15 7 Output: [3, 14.5, 11] Explanation:...

肉丸不肉 489

在 SAP GUI 里开发与调用 Adobe PDF 表单:SFP 建模 + Driver Program 调用的全流程实战

本文介绍了在SAP系统中使用Adobe PDF表单的完整流程。重点阐述了SAP Interactive Forms相比传统表单工具的优势,特别是在处理复杂排版、条码和交互式字段时的适用性。文章详细说明了开发流程:从安装设计工具Adobe LiveCycle Designer开始,到在SFP事务码中创建Interface和Form的数据模型,再到编写驱动程序的ABAP代码实现PDF输出。特别强调了Interface作为数据契约的重要性,以及如何通过分层设计实现前后端分离开发。最后提供了标准调用链的示例代码,展

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

[LeetCode]637. Average of Levels in Binary Tree

[LeetCode]637. Average of Levels in Binary Tree题目描述思路实际上是树的层次遍历 递归写法参数中加入层数即可代码#include <iostream> #include <vector>using namespace std;struct TreeNode { int val; TreeNode* left; TreeNode*

Lcharon的博客 834

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

[LeetCode][637]Average of Levels in Binary Tree题解

[LeetCode][637]Average of Levels in Binary Tree题解 标签:BFS queue 题意:求树的每层的平均数 使用bfs即可 code: /* * [637] Average of Levels in Binary Tree * * https://leetcode.com/problems/average-of-levels-in-binary-...

OCEANtroye的博客 300

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

Leetcode 637. Average of Levels in Binary Tree

Given a non-empty binary tree, return the average value of the nodes on each level in the form of an array. Example 1: Input: 3 / \ 9 20 / \ 15 7 Output: [3, 14.5, 11]...

ahdctjv534913的博客 97

Leetcode——637. Average of Levels in Binary Tree

题目原址 https://leetcode.com/problems/average-of-levels-in-binary-tree/description/ 题目描述 Given a non-empty binary tree, return the average value of the nodes on each level in the form of an array. E...

想当厨子的程序媛 290

27.leetCode637:Average of Levels in Binary Tree

题目:Given a non-empty binary tree, return the average value of the nodes on each level in the form of an array. Example 1: Input: 3 / \ 9 20 / \ 15 7 Output: [3, 14.5, 11]

wjx_sky的博客 279

LeetCode 637. Average of Levels in Binary Tree

LeetCode 637. Average of Levels in Binary Tree (Easy) 主要知识点:树;优先级:4(递归方法)

温迪今天刷题了吗 606

leetcode-637. Average of Levels in Binary Tree (C语言,层次遍历,队列实现)

637. Average of Levels in Binary Tree Method:层次遍历,将每一层的所有TreeNode都存储在一个临时队列Queue里面,再循环遍历每一层。用c语言的话需要自己创建队列Queue,即一个Queue中的每个QNode是TreeNode类型的,还要实现它的enQueue操作。 /**  * Definition for a binary tree nod...

Shirleylinyuer的专栏 457

Golang Leetcode 637. Average of Levels in Binary Tree.go

思路 用队列保存节点,一层一层的处理 从队列里取出节点的同时,判断左右子树是否为空,不为空则入队列 code func averageOfLevels1(root *TreeNode) []float64 { ret := []float64{} if root == nil { return ret } cnt, sum := 0, 0 q := []*TreeNode{root}...

anakinsun的博客 188

[Swift]LeetCode637. 二叉树的层平均值 | Average of Levels in Binary Tree

★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs.com/strengthen/)➤GitHub地址:https://github.com/strengthen/LeetCode➤原文地址:https://www.cnblogs.com/stren...

weixin_30781433的博客 128

python leetcode 637. Average of Levels in Binary Tree

Given a non-empty binary tree, return the average value of the nodes on each level in the form of an array.求二叉树中每层的均值。515. Find Largest Value in Each Tree Row513. Find Bottom Left Tree ValueExample 1:...

DreamerLHQ的博客 358

Leetcode 637.Average of Levels in Binary Tree(一棵树每层节点的平均数)

用广度优先遍历做 唯一不一样的是在while(队不空)是要用一个for循环(是n即队列的长度 )来计算每层节点的和 Given a non-empty binary tree, return the average value of the nodes on each level in the form of an array Example 1: Input: 3 / \ ...

秀秀的奇妙旅行 210

leetcode 637. Average of Levels in Binary Tree(java easy)

题目: Given a non-empty binary tree, return the average value of the nodes on each level in the form of an array.  Example: Input: 3 / \ 9 20 / \ 15 7 Output: [3, 14.5, 11] Ex

Ellenfeifei的博客 471
上一篇: leetcode 623. Add One Row to Tree( 在二叉树中增加一行)
下一篇: leetcode 652. Find Duplicate Subtrees(找出重复的子树)
蓝羽飞鸟
博客等级 码龄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、付费专栏及课程。

余额充值
⌂ 换网址