(力扣记录)199.二叉树的右视图

SE模块理解+SE-Resnet模块pytorch实现 文章目录SE模块理解SE实现注意力机制原因SE-resnet网络pytorch实现定义residual定义SE模块 SE模块理解 SENet是Squeeze-and-Excitation Networks的简称,拿到了ImageNet2017分类比赛冠军,其效果得到了认可,其提出的SE模块思想简单,易于实现,并且很容易可以加载到现有的网络模型框架中。SENet主要是学习了channel之间的相关性,筛选出了针对通道的注意力,稍微增加了一点计算量,但是效果比较好。 SE模块广泛应用于去噪,去雨方向,利用SE模 阅读详情

数据结构:树🌲

时间复杂度:O(n)

空间复杂度:O(n)

代码实现:

class Solution:
    def rightSideView(self, root: Optional[TreeNode]) -> List[int]:
        if not root: return []
        q = [root]
        res = []
        while q:
            out = None
            for _ in range(len(q)):
                out = q.pop(0)
                if out.left:
                    q.append(out.left)
                if out.right:
                    q.append(out.right)
            res.append(out.val)
        
        return res

深度学习工具包 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") 立即下载

相关推荐

支持找回微信删除好友!一款人人可用的全能微信数据分析工具

找回删除好友、查看删除记录、恢复聊天信息....

1725

LeetCode做题记录—LeetCode199:二叉树的右视图—JAVA语言实现

LeetCode199:二叉树的右视图 题目描述: 给定一棵二叉树,想象自己站在它的右侧,按照从顶部到底部的顺序,返回从右侧所能看到的节点值。 示例: 输入: [1,2,3,null,5,null,4] 输出: [1, 3, 4] 代码实现 方案一: 通过深度优先搜索,按照根 - > 右 - > 左的遍历方式,保证对于每一层而言能先访问到其最右侧的节点。同时设立变量max_dept...

J_York的博客 368

Visio中高效绘制空间坐标系的实用技巧

本文详细介绍了在Visio中从零开始高效绘制精准空间坐标系的实用技巧。文章摒弃了现成形状的局限,重点讲解了如何利用直线、箭头和文本框等基础工具,结合网格设置、绘图比例调整和图层管理,构建完全可控的三维坐标系。通过分步指南,帮助用户掌握刻度添加、标注对齐及模板创建等高级方法,从而在科研绘图与工程制图中实现专业级的视觉效果。

e3f4g5的博客 558

力扣 199题 二叉树的右视图 记录

层次遍历,当遍历到每一层的最后的一个节点的时候,将该节点的值放入 result 数组中。

m0_49800270的博客 310

TSmaster CANFD配置避坑指南:为什么你的PCAN盒不支持最新版本?

本文针对TSmaster配置PCAN硬件进行CANFD通信时的常见问题,提供了详细的避坑指南。重点解析了CANFD配置中TSEG1等关键参数的理解误区,并深入探讨了TSmaster新版本与PCAN硬件驱动之间的兼容性变化,帮助工程师快速定位并解决连接失败或无法发送CANFD报文等问题。

alpha的博客 542

别再死记硬背了!用‘小乌龟’实战图解ROS1核心指令(rosnode/rostopic/rosparam保姆级手册)

本文通过经典的turtlesim乌龟仿真器,以可视化实战方式讲解ROS1核心指令(rosnode/rostopic/rosparam),帮助初学者摆脱死记硬背,在操控乌龟的过程中轻松掌握节点管理、话题通信和参数设置等ROS1核心概念。

weixin_28731223的博客 370

【Leetcode题目记录199】——二叉树的右视图

最后取出子节点的子节点的子节点的......子节点的子节点,放入出子节点的子节点的子节点的......子节点的子节的子节点........每一次取出,都把取出的节点值放在一个列表中,记录为这颗二叉树这一层中的值,然后将最后一个值放入最后要作为答案返回的列表中。即创建一个队列Queue,将二叉树放入队列中,此时可以直接从队列中获取到根节点的值。,想象自己站在它的右侧,按照从顶部到底部的顺序,返回从右侧所能看到的节点值。在之后,继续从队列中把之前放入的子节点都取出,再放入子节点的子节点...

2401_84371076的博客 363

STM32掉电保存配置参数技巧

本文介绍了使用STM32内置备份寄存器(BKP)实现掉电保存配置参数的方法。相比外接EEPROM或Flash,备份寄存器无需外设但存储容量有限,需通过VBAT引脚连接纽扣电池供电。文章详细说明了初始化步骤,包括使能PWR时钟、允许访问备份寄存器等操作,并提供了RTC初始化的代码示例。同时介绍了HAL库中读写备份寄存器的函数使用方法,包括HAL_RTCEx_BKUPWrite和HAL_RTCEx_BKUPRead函数的具体参数和调用示例。该方法适用于需要小容量数据掉电保存的应用场景。

hanhanhan233的博客 946

Leetcode刷题记录——199. 二叉树的右视图

用一个全局数组记录结果 递归时记录深度 优先搜索右子树 当递归到第i层,且当前结果长度<i时,计入这个节点的值 # Definition for a binary tree node. # class TreeNode: # def __init__(self, x): # self.val = x # self.left = None # self.right = None class Solution: def __init__(.

1996MZH的博客 176

从零构建工业级SPI-CAN网关:CH347与CH9431的软硬件协同设计实战

本文详细介绍了基于CH347和CH9431芯片构建工业级SPI-CAN网关的完整方案。通过硬件架构设计、Linux驱动定制、并发处理优化和EMC抗干扰测试,实现高可靠性通信网关,适用于工业自动化和汽车电子等严苛环境。

spark7igniter的博客 632

java项目反编译工具记录,共计6个工具

java项目反编译工具记录,共计6个工具

橙-极纪元-JJYCheng 1801

leetcode刷题记录(七十七)——199. 二叉树的右视图

因此解决的思路就是层序遍历,把每一层最后一个节点的值记录下来就可以了。

weixin_45994787的博客 1033

[QMT量化交易小白入门]-五十、十年基本保证每年盈利,全天ETF候稳稳的幸福

全局参数raise_rate = -1 # 触发rebalance的上涨比例period: 设定为22,表示每22个交易日执行一次调仓(即大约每月一次)。这是策略的时间框架基础。raise_rate: 初始值设为-1,意味着默认情况下不会因为资产的涨幅而触发调仓。这一参数用于控制是否基于资产表现动态调整仓位。run_count: 用于记录策略运行的次数,帮助判断何时执行定期调仓。1、为了简便计算,回撤时将调仓再平衡是先卖出再买入,没有比较持仓,实盘时是需要计算的,减少交易费用。

木头大左的博客 806

Leetcode 199.二叉树的右视图(层序遍历) 记录反思

一开始想简单了,还以为右子节点一定有值,结果 [1,2] … class Solution { List<Integer> list = new ArrayList<>(); public List<Integer> rightSideView(TreeNode root) { if(root == null){ return list; } Deque<TreeNode&gt.

weixin_45935610的博客 162

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

android 蓝牙通讯demo

android 下蓝牙通讯demo,实现了发现蓝牙,使能蓝牙,通过蓝牙发送消息。

199. 二叉树的右视图【JS】

199. 二叉树的右视图 解题思路 将每一层遍历结果数组的最后一位,作为该层能够看到的“右视图”的值。 代码 /** * Definition for a binary tree node. * function TreeNode(val) { * this.val = val; * this.left = this.right = null; * } */ /** ...

Janejie_Zhou的博客 300

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

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

LeetCode:199 二叉树右视图 层次遍历解法

LeetCode:199 二叉树右视图 层次遍历解法 【传送门】 题目描述 给定一棵二叉树,想象自己站在它的右侧,按照从顶部到底部的顺序,返回从右侧所能看到的节点值。 示例: 输入: [1,2,3,null,5,null,4] 输出: [1, 3, 4] 解释: 来源:力扣(LeetCode) 链接:https://leetcode-cn.com/problems/binary-tree-ri...

AKGWSB 's blog 264

jre9下载 jdk9

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

python-leetcode-二叉树的右视图

【代码】python-leetcode-二叉树的右视图。

Lucy_wzw的博客 435

Leetcode 199 二叉树的右视图

最近依旧每天在刷一道新题的同时复习一道忘了的旧题,今天复习的忘了的旧题就是leetcode 199 二叉树的右视图,我的确忘了具体代码怎么写了,但是我记得这是我当初第一次真正意义上自己思考并写出来的一道中等题,还是记忆犹新的。 给定一棵二叉树,想象自己站在它的右侧,按照从顶部到底部的顺序,返回从右侧所能看到的节点值。 输入: [1,2,3,null,5,null,4] 输出: [1, 3, 4] 解释: 1 <— / 2 3 <— \

yan_5的博客 342

Leetcode 199. 二叉树的右视图 层序遍历

本文介绍了Leetcode 199题"二叉树的右视图"的层序遍历解法。题目要求返回从右侧观察二叉树时能看到的节点值序列。给出的C++解决方案使用BFS层序遍历,在每层处理时记录第一个节点值(即最右侧节点),然后优先将右子节点入队,再处理左子节点。这种方法确保每层的最右侧节点被首先访问并记录,时间复杂度为O(n),空间复杂度为O(n)。代码简洁高效,通过队列实现层序遍历,最终返回右视图的节点值序列。

想买很多漂亮衣服但是买不起的博客 250

LeetCode - 199. 二叉树的右视图

DFS访问顺序(先右后左)是:1 -> 3 -> 6 -> 2 -> 5 -> 4。右视图是指从树的右侧看,对于每一层,只能看到该层最右边的节点。最终result=[1,3,6],正好是树的右视图。如果当前节为空,直接返回检查当前深度是否等于结果数组的长度如果是,说明这是当前深度第一个被访问的节点,将其值加入结果数组如果不是,说明该深度已经有节点被加入结果,不做操作先递归访问右子树(深度+1),再递归访问左子树(深度+1)

2402_83315537的博客 1201

Leetcode之深度优先搜索(DFS)专题-199. 二叉树的右视图(Binary Tree Right Side View)...

Leetcode之深度优先搜索(DFS)专题-199. 二叉树的右视图(Binary Tree Right Side View) 深度优先搜索的解题详细介绍,点击 给定一棵二叉树,想象自己站在它的右侧,按照从顶部到底部的顺序,返回从右侧所能看到的节点值。 示例: 输入:[1,2,3,null,5,null,4] 输出:[1, 3, 4] 解释: 1 ...

denghan1065的博客 688

Leetcode 199. 二叉树的右视图 C++

Leetcode 199. 二叉树的右视图 题目 给定一棵二叉树,想象自己站在它的右侧,按照从顶部到底部的顺序,返回从右侧所能看到的节点值。 示例: 输入: [1,2,3,null,5,null,4] 输出: [1, 3, 4] 解释: 1 <--- / \ 2 3 <--- \ \ 5 4 <--- 题解 我们可以尽可能的先遍历右子树,按照中右左的方式进行。另外用一个哈希表记录第i层

weixin_43750513的博客 184

LeetCode199:二叉树的右视图

LeetCode199:二叉树的右视图 给定一个二叉树的 根节点 root,想象自己站在它的右侧,按照从顶部到底部的顺序,返回从右侧所能看到的节点值。

RitaAndWakaka的博客 673

199. 二叉树的右视图

199. 二叉树的右视图: 题目链接 :199. 二叉树的右视图 题目: 给定一个二叉树的 根节点 root,想象自己站在它的右侧,按照从顶部到底部的顺序,返回从右侧所能看到的节点值。 思路: 1、BFS (1)广度优先:对树的每层进行根-左-右的顺序遍历存入队列 (2)那么每层最后一个入队的元素就是我们需要的最右元素 (3)进行N层遍历,N==队列.size() 2、DFS (1)深度优先:依照根右左的顺序遍历,保证右子树先入队 (2)设定深度值,即标识当前层数 (3)又因为保证了根左右的顺序,所以我

weixin_45750855的博客 2627

LeetCode 热题 100 -- 199. 二叉树的右视图

给定一个二叉树的 根节点 root,想象自己站在它的右侧,按照从顶部到底部的顺序,返回从右侧所能看到的节点值。输入:root = [1,2,3,4,null,null,null,5]输入:root = [1,2,3,null,5,null,4]使用队列进行层序遍历,记录每层的最后一个节点值。输入:root = [1,null,3]二叉树的节点个数的范围是 [0,100]输出:[1,3,4,5]输入:root = []输出:[1,3,4]

qq_74980411的博客 304

【LeetCode】 199. Binary Tree Right Side View 二叉树的右视图(Medium)(JAVA)每日一题

【LeetCode】 199. Binary Tree Right Side View 二叉树的右视图(Medium)(JAVA) 题目地址: https://leetcode-cn.com/problems/binary-tree-right-side-view/ 题目描述: Given a binary tree, imagine yourself standing on the right ...

qq_16927853的博客 225
上一篇: (力扣记录)102. 二叉树的层序遍历
下一篇: (力扣记录)1448. 统计二叉树中好节点的数目
Wilson_ZheLIN
博客等级 码龄5年 684粉丝 28原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值