/*
思路:
从右边看,并不是指右节点--也就是每层最右边的节点,则考虑层次遍历只取最右
*/
public class Solution {
public List<Integer> rightSideView(TreeNode root) {
List<Integer> list = new LinkedList<Integer>();
Queue<TreeNode> queue = new LinkedList<TreeNode>();
if(root == null) {
return list;
}
queue.add(root);
while(!queue.isEmpty()) {
int m = queue.size();
while(m > 0) {
TreeNode node = queue.remove();
if(node.left != null) {
queue.add(node.left);
}
if(node.right != null) {
queue.add(node.right);
}
m--;
if(m == 0) {
list.add(node.val);
}
}
}
return list;
}
}
相关推荐
松灵机器人——ROS下的CAN通讯调试(内含所需调用包,都是操作步骤)
松灵机器人——ROS下的CAN通讯调试(都是操作步骤) 1 代码包地址 scout_ros package:https://github.com/westonrobot/scout_ros.git ugv_sdk-main package:https://github.com/westonrobot/ugv_sdk webots package:https://cyberbotics.com/ 2 硬件准备 2.1 SCOUT MINI 小白车 + 尾部航空插头 + CAN_TO_USB适配器
LeetCode二叉树系列——199二叉树的右视图
刚刚我们说过了二叉树有两种存储方式顺序存储,和链式存储,顺序存储就是用数组来存,这个定义没啥可说的,我们来看看链式存储的二叉树节点的定义方式。intval;};大家会发现二叉树的定义和链表是差不多的,相对于链表,二叉树的节点里多了一个指针,有两个指针,指向左右孩子。这里要提醒大家要注意二叉树节点定义的书写方式。在现场面试的时候面试官可能要求手写代码,所以数据结构的定义以及简单逻辑的代码一定要锻炼白纸写出来。二叉树是一种基础数据结构,在算法面试中都是常客,也是众多数据结构的基石。...
密码学:一文读懂数字证书
消息摘要算法用于验证数据完整性服务,对称加密算法和非对称加密算法用于保证数据保密性服务,数字签名算法用于抗否认性服务。数字证书集合了多种密码学算法:自身带有公钥信息,可完成相应的加密/解密操作;同时,还带有数字签名,可鉴别消息来源;且自身带有消息摘要信息,可验证证书的完整性;由于证书本身含有用户身份信息,因而具有认证性。
LeetCode第199题--二叉树的右视图
给定一棵二叉树,想象自己站在它的右侧,按照从顶部到底部的顺序,返回从右侧所能看到的节点值。 示例: 输入: [1,2,3,null,5,null,4] 输出: [1, 3, 4] 解释: 1 <--- / \ 2 3 <--- \ \ 5 4 <--- /** * Definitio...
别再凭感觉选电容了!手把手教你计算电机控制器里的母线电容(附Excel计算工具)
本文详细解析了电机控制器中母线电容的选型方法,从理论计算到工程实践,帮助工程师避免常见误区。通过精确计算纹波电压、电容容量等关键参数,并结合薄膜电容与电解电容的性能对比,提供实用的选型建议。附带的Excel计算工具可快速完成参数计算,适用于工业伺服驱动和电动车电机控制器设计。
英飞凌TC377的Flash管理、UCB配置与HSM安全机制解析
本文深入解析了英飞凌TC377微控制器的Flash存储结构、UCB配置机制与HSM安全模块。详细阐述了带Cache与不带Cache的PFlash地址访问差异、利用SOTA与AB Swap实现无感OTA更新的原理,以及如何通过UCB安全配置启动流程与写保护。重点剖析了HSM硬件安全模块在密钥管理、安全启动与安全OTA中的核心作用,为开发高可靠性嵌入式系统提供实战指南。
力扣(LeetCode)199. 二叉树的右视图(C++)
【墨染】层序遍历的迭代&根右左递归。
Python实战:解析腾讯视频M3U8加密链接并下载高清影片
本文详细介绍了如何使用Python解析腾讯视频M3U8加密链接并下载高清影片。从环境准备、抓包分析到核心代码实现,逐步讲解如何获取M3U8主链接、解析TS分片列表以及下载合并视频片段。文章还提供了多线程下载、断点续传和加密视频处理等优化方案,帮助开发者高效完成视频下载任务。
LeetCode199之二叉树的右视图(二叉树的深度遍历和广度遍历)
这题如果没有接触过二叉树的深度遍历和广度遍历其实是很难自己做出来的
深度学习笔记——Transformer
本文详细介绍面试过程中可能遇到的Transformer知识点。
KEPServerEX 6 之 EX 6.11.718.0 发布说明
KEPServerEX 6.11.718.0 发布说明
Leetcode-199二叉树的右视图(二叉树左视图)
采用一个队列+计数的方法,每个层次的遍历,之前,都先统计一下这一层有多少个节点。队列有n个节点,当这一层级的第n个节目点出栈的时候,将该节点计入结果。
BP神经网络回归预测+SHAP可解释分析+新数据预测(MATLAB完整源码)
BP神经网络回归预测+SHAP可解释分析+新数据预测(MATLAB完整源码)
【LeetCode】199. Binary Tree Right Side View 二叉树的右视图(Medium)(JAVA)
【LeetCode】199. Binary Tree Right Side View 二叉树的右视图(Medium)(JAVA) 题目地址: https://leetcode.com/problems/binary-tree-right-side-view/ 题目描述: Given a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see order
VC中sqlite的使用
在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示
Devexpress16.2.6破解工具
Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具
[JAVA]LeetCode199 Binary Tree Right Side View
Given a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bottom.For example: Given the following binary tree, 1
计算机控制技术及应用
《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。
Leetcode199.二叉树的右视图 Binary Tree Right Side View(Java)
Leetcode199.二叉树的右视图 Binary Tree Right Side View(Java) ##Tree##, ##Depth-first Search##, ##Breadth-first Search## 本题要求每一层的最右边元素,可以使用DFS、BFS 使用BFS的层次遍历更直观 BFS层次遍历做法 队列q中的元素为某一层的所有元素,count代表该层的元素个数,即count = q.size() count次循环,将队列q中的结点出队,并将每个遍历的结点的左结点和右结点加入到队列
LinePhone3.2.7(android端最新版本) sip客户端
SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/
leetcode oj java 199. Binary Tree Right Side View
一、问题描述: Given a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bottom. For example: Given the following binary
[LeetCode] 199. Binary Tree Right Side View Java
题目: Given a binary tree, imagine yourself standing on therightside of it, return the values of the nodes you can see ordered from top to bottom. For example:Given the following binary tree, ...
[leetcode-199]Binary Tree Right Side View(java)
问题描述: Given a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bottom.For example: Given the following binary tree, 1
leetcode 199. Binary Tree Right Side View | 199. 二叉树的右视图(Java)
题目 https://leetcode-cn.com/problems/binary-tree-right-side-view/ 题解 本题思路来源于二叉树的层序遍历。 层序遍历类似问题:leetcode 637. Average of Levels in Binary Tree 如何使用“记录下一行最右节点”的方式,进行层序遍历:左神算法:二叉树的按层打印与ZigZag打印 /** * Definition for a binary tree node. * public class TreeN
Java描述 LeetCode,199. Binary Tree Right Side View 站在二叉树的右侧 看树
大家好,我是河海哥,专注于后端,如果可以的话,想做一名code designer而不是普通的coder,一起见证河海哥的成长,您的评论与赞是我的最大动力,如有错误还请不吝赐教,万分感谢。一起支持原创吧!纯手打有笔误还望谅解。 1-1:description Given the root of a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can se.
Java for LeetCode 199 Binary Tree Right Side View
Given a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bottom. For example: Given the following binary tree, 1 ...
【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 ...
LeetCode-199. Binary Tree Right Side View (JAVA)(二叉树最右侧结点)
LeetCode-199. Binary Tree Right Side View (JAVA)(二叉树最右侧结点)
(Java)leetcode-199 Binary Tree Right Side View(二叉树的右视图)
BFS,DFS
leetcode 199. Binary Tree Right Side View-树的右视图|递归|非递归|Java|Python
原题链接:199. Binary Tree Right Side View 【思路】非递归实现 层次遍历,每一层都是从左到右遍历,将每一层的最右一个节点添加到结果集中就是我们需要得到的结果: public class Solution { public List rightSideView(TreeNode root) { List res = new ArrayLi
1万+



被折叠的 条评论
为什么被折叠?



