[Leetcode] 637. Average of Levels in Binary Tree

开源生成式推荐框架MiniOneRec实践:从SID构建到RL微调全解析 在推荐系统领域,从协同过滤到深度学习,核心目标始终是精准预测用户兴趣。其技术原理经历了从矩阵分解到深度神经网络的演进,旨在从海量用户行为数据中挖掘复杂模式。随着大语言模型(LLM)的兴起,生成式推荐作为一种新兴范式,将推荐问题重构为序列生成任务,展现出更强的泛化能力和端到端优化潜力,尤其适合处理动态、多模态的推荐场景。本文聚焦于首个完全开源的生成式推荐框架MiniOneRec,它通过引入语义商品ID(SID)解决物品离散化难题,并采用监督微调(SFT)与强化学习(RL)结合的完整训练流程,为工程师和研究者提 阅读详情

Description:

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:

  1. The range of node's value is in the range of 32-bit signed integer.

 

 

/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode(int x) { val = x; }
 * }
 */
class Solution {
    public List<Double> averageOfLevels(TreeNode root) {
        List <Double> result = new ArrayList<>();
        Queue<TreeNode> test = new LinkedList<>();
        test.add(root);
        while (!test.isEmpty()){
            int num = test.size();
            double sum = 0.0;
            for (int i = 0; i < num; i++) {
                TreeNode x = test.poll();
                sum = sum + x.val;
                if (x.left != null)
                    test.add(x.left);
                if (x.right != null)
                    test.add(x.right);                               
            }
            result.add(sum/num);
        }
        return result;
    }
}

 

p.s. 这里使用了queue来统计每一层element的个数!

 

PCB板设置20H 原则理解 20H原则是PCB设计中抑制EMI辐射的关键方法,要求电源层比相邻地层内缩20倍介质厚度(20H)。在四层板中实现20H原则需采用S-G-P-S层叠结构,确保GND与PWR紧邻。具体步骤包括:确定GND-PWR间介质厚度H,计算20H值(通常80-120mil),并在设计软件中将电源层四周内缩20H,同时保持地层完整不内缩。注意避免常见误区,如混淆介质厚度、地层内缩等。该原则能有效限制边缘场辐射,降低EMI干扰,是四层板EMC设计的重要规范。 阅读详情

相关推荐

Win11网络卡顿?用Wireshark抓包5分钟定位问题(保姆级实战)

本文详细介绍了如何使用Wireshark在Win11系统中快速定位网络卡顿问题。通过5分钟抓包分析,作者成功发现TCP重传率高达37%的罪魁祸首,并提供了从准备工作到实战分析的保姆级教程,帮助用户解决游戏卡顿、视频会议延迟等常见网络问题。

weixin_28839629的博客 308

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

利用OrthoFinder做泛基因家族聚类分析

这条命令会将 Arabidopsis_thaliana.TAIR10.59_longest_trans.pep.fa 文件中的所有序列ID,去掉ID中的空格后面的部分,只保留 > 后第一个空格之前的基因ID,并将结果保存在 An1.fasta 文件中。muscle 是一种常用的多序列比对工具,用于基因组或蛋白质序列的比对。基因家族(Gene family),是来源于同一个祖先,由一个基因通过基因重复而产生两个或更多的拷贝而构成的一组基因,它们在结构和功能上具有明显的相似性,编码相似的蛋白质产物。

qq_64400864的博客 2759

【Leetcode】637. Average of Levels in Binary Tree

求二叉树每一层的平局值 思路 其实就是层次遍历的方法,再除以每层的节点数就行了,层次遍历的各种写法都可以用 方法1 深搜非递归 class Solution1(object): def averageOfLevels(self, root): &quot;&quot;&quot; :type root: TreeNode :rtype: List[float] ...

很吵请安静 451

光谱预处理最简单实现方法--基于OpenSA光谱分析库

系列文章目录 “光晰本质,谱见不同”,光谱作为物质的指纹,被广泛应用于成分分析中。伴随微型光谱仪/光谱成像仪的发展与普及,基于光谱的分析技术将不只停留于工业和实验室,即将走入生活,实现万物感知,见微知著。本系列文章致力于光谱分析技术的科普和应用。 文章目录系列文章目录前言一、数据来源二、代码解读2.1 读取数据2 .2 划分数据集2 .3 返回训练集和测试集并绘制光谱图片2.4 建立1-D CNN模型2.5 训练1-D CNN模型2.6 测试1-D CNN模型2.7 运行CNN模型,并用查看结果总结

Echo_Code的博客 7069

JDK8升级JDK17过程中遇到的那些坑

JDK8虽然非常好,但是JDK版本已经发布到JDK20了,且JDK8后的版本升级了很多新的特性,如模块化、ZGC以及虚拟线程、结构性并发等,也是非常有吸引力的,所以决定将基于JDK8的项目升级到最近的LTS版本JDK17。

BASK2312的博客 6686

Leetcode 637 Average of Levels in Binary Tree

题目链接: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...

Mereder的博客 181

深入探讨 VQ-VAE:理解变分量化自动编码器

VQ-VAE代表"Variational Quantized Variational Autoencoder",是一种生成模型,通常用于处理高维数据,如图像和音频。它的设计灵感来自于变分自动编码器(VAE)和量化方法,结合了它们的优点,使得 VQ-VAE 能够生成高质量的数据,并在数据表示上引入离散性。VQ-VAE 是一种强大的生成模型,结合了变分自动编码器和量化方法的优点。它在图像和音频生成、数据压缩和生成性对抗网络等领域具有广泛的应用。

DeepViewInsight的博客 7017

LeetCode 637. Average of Levels in Binary Tree

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

weixin_30648963的博客 272

Qt(C++)使用QChart动态显示3个设备的温度变化曲线

Qt的QChart是一个用于绘制图表和可视化数据的类。提供了一个灵活的、可扩展的、跨平台的图表绘制解决方案,可以用于各种应用程序,如数据分析、科学计算、金融交易等。

1917

利用autojs制作抢购支付宝消费劵的手机脚本

前期准备工作 1.打开支付宝,点击中间的抢消费券的广告 2.点击左上角,将抢购页面添加到首页 3.查看支付宝首页是否出现消费劵 . autojs代码 "auto"; functiontaskstart(){ sleep(1000); launchApp('支付宝'); toast("正在打开支付宝应用"); sleep(1000); varxf=textContains("消费").findOne().bounds(); ...

洛阳泰山的博客 1万+

[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的博客 299

15、SQL Server查询优化与CPU负载管理

本文深入探讨了SQL Server查询优化与CPU负载管理的关键技术,包括强制连接类型的使用、键查找问题的解决、索引设计的最佳实践、高CPU负载的排查与优化,以及并行性的利弊与调整策略。通过优化查询逻辑、合理设计索引、监控与管理CPU资源,可以显著提升SQL Server的性能和稳定性。适用于数据库开发人员和DBA进行性能调优参考。

pz8901234的博客 80

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

想当厨子的程序媛 289

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

老版QQ原生表情gif动态

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

[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的博客 267

WINCC7.3破解文件

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

LeetCode 637 average of levels in binary tree

just use level traverse and calculate the average of each level. class Solution { public List<Double> averageOfLevels(TreeNode root) { List<Double> final_res = new ArrayList<>(); //List<List<Integer>> res =

Tech in Pieces 319

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

[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的博客 484

[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

【Leetcode】637. Average of Levels in Binary Tree(Easy)

1.题目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] Explanatio...

不想做菜鸟的小螃蟹 333

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, 1...

lxin_liu的博客 142

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

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] Explanati...

ghscarecrow的博客 174

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 (python+cpp)

Leetcode 637. Average of Levels in Binary Tree题目解法: 题目 解法: 这其实就是层级遍历,一般用bfs实现,两个循环嵌套,内循环负责遍历一层上所有节点 python代码如下: class Solution: def averageOfLevels(self, root: TreeNode) -> List[float]: q = collections.deque(); q.append(root)

qq_37821701的博客 286
上一篇: [Leetcode] 136. Single Number
下一篇: [Leetcode] 693. Binary Number with Alternating Bits
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值