java数据结构与算法刷题-----LeetCode637. 二叉树的层平均值

ABAP OO - ALV_TREE例程 项目上比较少有用到ALV_TREE的报表功能,刚好项目上有写了一次,也查阅大量的范例,整合了一写法,给自己做一下笔记。 程序包含功能按钮,按钮下拉,F4帮助,读取选中行,字段双击触发事件,字段前置图标,更新节点,获取节点数据,获取全部子节点,递归算法,DMS模块:创建文档功能,创建文档链接,SNRO创建流水号,缓存数据,下次用户加载进来继续操作。 *&---------------------------------------------------------------------* *&a 阅读详情
java数据结构与算法刷题目录(剑指Offer、LeetCode、ACM)-----主目录-----持续更新(进不去说明我没写完):https://blog.csdn.net/grd_java/article/details/123063846

在这里插入图片描述

解题思路:时间复杂度O(n),空间复杂度O(n)
  1. 使用广度优先遍历,按层遍历即可,遍历过程中,记录每层的结点和,最后将其平均数求出
  2. 使用深度优先遍历,需要记录当前结点的层次,然后必须使用一个可以通过下标获取值的容器来记录每个结点值

深度遍历时,将当前结点值累加到当前结点所在层次对应的地方,也就是容器对应下标(下标代表层次)位置。

1. 广度优先

代码:给出两种代码思路,一种是普通做法,第二种是直接在生成容器时,静态构建,因此第二种非常快,作为扩展了解即可
  1. 普通方法
    在这里插入图片描述
class Solution {
    public List<Double> averageOfLevels(TreeNode root) {
        List<Double> list = new ArrayList<>();//答案
        Queue<TreeNode> bfs_queue = new LinkedList<>();//广度优先队列
        bfs_queue.offer(root);//根结点入队列
        while(!bfs_queue.isEmpty()){
            int size = bfs_queue.size();//获取当前层中结点个数
            long sum = 0;//记录当前层结点的和
            for(int i = 0;i<size;i++){//遍历当前层
                TreeNode poll = bfs_queue.poll();//出队列
                sum+=poll.val;//累加
                if(poll.left!=null) bfs_queue.offer(poll.left);
                if(poll.right!=null)bfs_queue.offer(poll.right);
            }
            list.add((double)sum/size);//计算平均值
        }
        return list;
    }
    
}
  1. 进阶方法
    在这里插入图片描述
import java.util.AbstractList;
class Solution {
    public static List<Double> averageOfLevels(TreeNode root) {
        return new AbstractList<Double>() {//直接构建抽象链表
            private final List<Double> list = new ArrayList<>();//此链表保存答案
            private final List<TreeNode> level = new ArrayList<>();//此链表用于深度优先遍历
            @Override
            public Double get(int index) {//此方法为重写链表构建方法,获取指定下标值
                init();//初始化链表
                return list.get(index);//获取值
            }
            @Override
            public int size() {//获取链表值
                init();
                return list.size();
            }
            void init() {//初始化链表
                if (list.isEmpty()) {//如果链表为空,就初始化
                    level.add(root);//广度优先初始化
                    while (!level.isEmpty()) {
                        levelTraverse(level);
                    }
                }
            }
            //广度优先逻辑,统计每层的平均值
            void levelTraverse(List<TreeNode> level) {
                int count = level.size();
                long sum = 0;
                for (int i = 0; i < count; i++) {
                    TreeNode tree = level.get(0);
                    sum += tree.val;
                    if (tree.left != null) {
                        level.add(tree.left);
                    }
                    if (tree.right != null) {
                        level.add(tree.right);
                    }
                    level.remove(0);
                }
                list.add((double) sum / count);
            }
        };
    }
}

2. 深度优先

代码

在这里插入图片描述

class Solution {
    public List<Double> averageOfLevels(TreeNode root) {
        List<Integer> counts = new ArrayList<Integer>();//保存每层有几个结点
        List<Double> sums = new ArrayList<Double>();//保存每层结点累加和
        dfs(root, 0, counts, sums);
        List<Double> averages = new ArrayList<Double>();//保存答案
        int size = sums.size();
        for (int i = 0; i < size; i++) {//将每一层累加的结果进行求平均值
            averages.add(sums.get(i) / counts.get(i));
        }
        return averages;
    }

    public void dfs(TreeNode root, int level, List<Integer> counts, List<Double> sums) {
        if (root == null) return;
        if (level < sums.size()) {//如果当前层次不是第一次到达
            sums.set(level, sums.get(level) + root.val);//对应层累加
            counts.set(level, counts.get(level) + 1);//对应层结点个数+1
        } else {//如果第一次到达当前层,创建层次,当前结点值为当前层第一个结点,当前层结点个数为1
            sums.add(1.0 * root.val);//
            counts.add(1);
        }
        //继续遍历
        dfs(root.left, level + 1, counts, sums);
        dfs(root.right, level + 1, counts, sums);
    }
}
mcgs数据查表功能,用于大量数据对比查找对应数据,减少PLC代码 mcgs脚本实现数据查表功能 阅读详情

相关推荐

DSP28335做FFT傅里叶变换

1. 看了一下例程,居然没有FFT的例程,难道这个DSP28335不能做FFT吗?对了C2000系列是有C2000 ware这个库的。方便很多,不过目前不确定在C5000上运行的FFT能直接迁移到DSP28335上行不?测试了一下,是可以的,因为都是用的math.h,下面的一些正弦函数基本一样的 2. 硬件简介,其中DSP28335和TLV320AIC23B之间使用I2C接口进行寄存器配置,...

weixin_30390075的博客 3335

Java实现 LeetCode 637 二叉树的层平均值(遍历树)

637. 二叉树的层平均值 给定一个非空二叉树, 返回一个由每层节点平均值组成的数组. 示例 1: 输入: 3 / \ 9 20 / \ 15 7 输出: [3, 14.5, 11] 解释: 第0层的平均值是 3, 第1层是 14.5, 第2层是 11. 因此返回 [3, 14.5, 11]. 注意: 节点值的范围在32位有符号整数范围内。 /** *...

南 墙 1万+

创意视觉项目实战:用ESP32-S3+OV5640构建智能图像流系统

本文详细介绍了如何使用ESP32-S3开发板与OV5640摄像头模块构建智能图像流系统。从硬件连接到软件配置,涵盖Arduino环境搭建、图像采集优化、WiFi视频流传输及外设集成,为开发者提供完整的实战指南,助力智能家居和机器人视觉项目开发。

tech5的博客 1303

LeetCode题练习与总结:二叉树的层平均值--637

本文详细介绍了如何使用广度优先搜索算法计算二叉树每层节点的平均值,并提供了Java实现代码,分析了时间复杂度和空间复杂度,总结了涉及的关键知识点。

一直学习永不止步 1035

Mask2Former实战:用SwinTransformer+Deformable Attention搞定图像分割三大任务

本文实战解析了Mask2Former模型如何统一解决语义、实例和全景分割三大任务。通过集成Swin Transformer骨干网络与创新的Deformable Attention及Masked Attention机制,详细介绍了模型构建、训练策略及在COCO数据集上的性能表现,为开发者提供了高效的图像分割解决方案。

tech5的博客 248

【EMC电磁兼容】02.04——原理图的实战落地细节

原理图上的关于EMC的落地体现一、元器件的选型二、原理图上的EMC体现在哪里?1.芯片电源管脚滤波去耦:2.时钟电路滤波设计3.低速电路滤波抗干扰设计4.通讯接口电路的防护滤波5.系统输入电源端口电路的防护滤波6.系统接地的定义7.芯片软件功能的审查 一、元器件的选型 ​ 原理图最初设计涉及到选型元器件方面: 元器件选型 不仅仅功能需要满足要求,还需要考虑其它细节参数在不同应力下的反应,封装的不同也会产生不同的变化。 元器件替代 常常因为成本原因进行器件替代,除了要考虑功能参数相同时也要考虑系统参数

Time to Forget 2250

Leetcode刷题java之637. 二叉树的层平均值

执行结果: 通过 显示详情 执行用时 :5 ms, 在所有 Java 提交中击败了89.30% 的用户 内存消耗 :44.8 MB, 在所有 Java 提交中击败了59.61%的用户 题目: 给定一个非空二叉树, 返回一个由每层节点平均值组成的数组. 示例 1: 输入: 3 / \ 9 20 / \ 15 7 输出: [3, 14....

逆水行舟,不进则退 944

Windows10下RTABMAP+T265实现三维建图

win10+rtabmap+t265扫描地形

Suxiang1997的博客 3495

637. 二叉树的层平均值

LeetCode: 637. 二叉树的层平均值 思路: 树的层序遍历,使用到队列,先进先出 计算出每一层拥有多少个节点 从根节点加入 Queue 中,queue.size() — for 得出一层的节点数量, 先处理完一层 提交代码 public class Daily637 { public List<Double> averageOfLevels(TreeNode root) { List<Double> res = new ArrayLis

lankerens 317

【Altium designer】如何添加过孔阵列

按下图1指示,执行【Tool】菜单栏下【Via Stitching/Shielding】选项卡中的【Add Stitching to Net...】选项 图1 “添加过孔阵列”选项 点击【Add Stitching to Net...】选项后,会跳出一个窗口,让我们设置过孔阵列的参数信息,如下图2所示。 图2 过孔阵列参数设置 过孔阵列区域:勾选该选项框,即可绘制多边形区域; 过孔内径与焊盘直径:比如内径 【Hole Size】设为12mil,焊盘直径【Diameter】设为24mil; .

夜半少年的博客 2万+

基于FPGA的NCO实现

NCO实现原理 数字振荡器 输出频率,相位可控的正弦波,精度高,稳定性高,替代VCO,用起来方便也易于操作。 实现方式: 直接调用fpga里面的ip核,以下是IP核的配置方法: 接下来选择输出为单路还是多路: 最后生成ip核时需要注意的事项: 生成时会需要漫长的等待,因此需要如下操作: 最后成功生成: 实现代码: input clk ; input rst_n ; output [13:0]fsin_i ; wire [13:.

m0_46644103的博客 4586

leetcode刷题记录 637 二叉树的层平均值

leetcode 637 二叉树的层平均值 解题思路: 1.可以采取广度遍历,用两个queue存放结点,一个存放第i层的结点,另外一个存放下一层节点。然后遍历完一层就计算其平均值,存入list中。 class Solution { public List<Double> averageOfLevels(TreeNode root) { Queue<TreeNode> queue = new LinkedList<>(); List

weixin_40453090的博客 167

【ComfyUI】Wan2.2 Animate 背景保留动作迁移视频生成

本文介绍了一个基于ComfyUI的高精度视频生成工作流"Wan2.2 Animate",该系统融合动作捕捉、图像拼接和LoRA加权等技术,能自动识别人脸并完成精准动作迁移,同时保持背景稳定。工作流采用模块化设计,包含输入提取、图像融合、模型加载等关键节点,核心模型Wan2.2-Animate-14B支持fp8精度与BlockSwap控制。流程分为图像输入、动作提取、多图合成等五个阶段,通过文本提示编码器和图像语义编码器实现语义驱动的动作生成,最终输出高质量视频,适用于虚拟形象驱动和

Mr数据杨 2309

[LeetCode] 637.二叉树的层平均值(java实现)

[LeetCode] 637.二叉树的层平均值(java实现)1. 题目2. 读题(需要重点注意的东西)3. 解法4. 可能有帮助的前置习题5. 所用到的数据结构与算法思想6. 总结 1. 题目 637.二叉树的层平均值 给定一个非空二叉树, 返回一个由每层节点平均值组成的数组。 2. 读题(需要重点注意的东西) 难点在于如何控制每一层的输出。 3. 解法 解法:BFS /** * Definition for a binary tree node. * public class TreeNode {

cloud的博客 329

老版QQ原生表情gif动态

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

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

LeetCode 637. 二叉树的层平均值(Average of Levels in Binary Tree)

637. 二叉树的层平均值 637. Average of Levels in Binary Tree LeetCode637. Average of Levels in Binary Tree 题目描述 给定一个非空二叉树, 返回一个由每层节点平均值组成的数组. 示例 1: 输入: 3 / \ 9 20 / \ 15 7 输出: [3, 14.5, 11]...

weixin_30241919的博客 125

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

leetcode刷题记录

刷题过程记录

洪肥肥的博客 2063

IDEA的使用指南

IDEA基于java的使用手册,可以最快速的上手,在使用中不断的丰富自己的使用技巧.

【leetcode刷题记录】(java)二叉树

【leetcode刷题记录】(java)二叉树 刷题参考代码随想录:https://programmercarl.com/

南京大学软件工程硕士在读 1320

leetcode 637.二叉树的层平均值 Java

二叉树的层平均值题目链接描述示例代码BFSDFS 题目链接 https://leetcode-cn.com/problems/average-of-levels-in-binary-tree/ 描述 给定一个非空二叉树, 返回一个由每层节点平均值组成的数组。 示例 示例1 输入:[3,9,20,15,7] 输出:[3, 14.5, 11] 代码 BFS /** * Definition for a binary tree node. * public class TreeNode { *

博主是个二次元死肥宅~ 285

leetcode【每日一题】637. 二叉树的层平均值 Java

题干 给定一个非空二叉树, 返回一个由每层节点平均值组成的数组。 示例 1: 输入: 3 / \ 9 20 / \ 15 7 输出:[3, 14.5, 11] 解释: 第 0 层的平均值是 3 , 第1层是 14.5 , 第2层是 11 。因此返回 [3, 14.5, 11] 。 提示: 节点值的范围在32位有符号整数范围内。 想法 经典bfs啊 只需要每层的时候增加一个变量计算和 bfs实现: 使用队列,把根结点放入队列,当队列不为空的时候就循环 我们在每次取出

qq_43491066的博客 206

LeetCode 637. 二叉树的层平均值 JAVA

给定一个非空二叉树, 返回一个由每层节点平均值组成的数组。 示例 1: 输入: 3 / \ 9 20 / \ 15 7 输出:[3, 14.5, 11] 解释: 第 0 层的平均值是 3 , 第1层是 14.5 , 第2层是 11 。因此返回 [3, 14.5, 11] 。 提示: 节点值的范围在32位有符号整数范围内。 来源:力扣(LeetCode) 链接:https://leetcode-cn.com/problems/average-of-leve

sinb妃的博客 156

Leetcode 637.二叉树的层平均值

Leetcode 637.二叉树的层平均值 给定一个非空二叉树, 返回一个由每层节点平均值组成的数组. 示例1: 题目解释 从题意来看,这个就是二叉树层次遍历的变种题,所以如果掌握了二叉树的层次遍历,这个问题就迎刃而解。 方法解答 教科书般的解答,层次遍历,最先想到的肯定是队列。忘记了的同学赶紧捡起书本好好的复习一下。 代码: ...

Gary___的博客 614

leetcode 637. 二叉树的层平均值(两个栈)

二叉树的层平均值 给定一个非空二叉树, 返回一个由每层节点平均值组成的数组。 示例 1: 输入: 3 / \ 9 20 / \ 15 7 输出:[3, 14.5, 11] 解释: 第 0 层的平均值是 3 , 第1层是 14.5 , 第2层是 11 。因此返回 [3, 14.5, 11] 。 提示: 节点值的范围在32位有符号整数范围内。 解题思路 这题我使用两个栈去解决。 1.首先需要两个栈s1,s2,遍历第一层时,存入s1,然后从s1中开.

weixin_43960668的博客 182

【二叉树】Leetcode 637. 二叉树的层平均值【简单】

第 0 层的平均值为 3,第 1 层的平均值为 14.5,第 2 层的平均值为 11。因此返回 [3, 14.5, 11]。

FLGB 561

leetcode 637:二叉树层的平均值(详细解答+源代码)

给定一个非空二叉树, 返回一个由每层节点平均值组成的数组. 示例 1: 输入: 3 / 9 20 / 15 7 输出: [3, 14.5, 11] 解释: 第0层的平均值是 3, 第1层是 14.5, 第2层是 11. 因此返回 [3, 14.5, 11]. 注意: 节点值的范围在32位有符号整数范围内。 基本思路: 这个问题本质是层次遍历,但是在层次遍历的基础上要增加对每层的叶子节...

weixin_43484977的博客 293
上一篇: java数据结构与算法刷题-----LeetCode671. 二叉树中第二小的节点
下一篇: java数据结构与算法刷题-----LeetCode230. 二叉搜索树中第K小的元素
ydenergy_殷志鹏
博客等级 码龄7年 5895粉丝 543原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

打赏作者

ydenergy_殷志鹏

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

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

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

打赏作者

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

抵扣说明:

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

余额充值
⌂ 换网址