当前位置:网站首页>2022.6.24-----leetcode. five hundred and fifteen
2022.6.24-----leetcode. five hundred and fifteen
2022-06-26 03:47:00 【Lu 727】
List<Integer> ans;
Deque<TreeNode> q;
public List<Integer> largestValues(TreeNode root) {
ans=new ArrayList<>();
q=new ArrayDeque<>();
if(root!=null)
q.add(root);
bfs();
return ans;
}
// By layer Sequence traversal
void bfs(){
if(q.isEmpty()) return;
int max=Integer.MIN_VALUE;
int n=q.size();
for(int i=0;i<n;i++){
TreeNode cur=q.poll();
max=Math.max(max,cur.val);
if(cur.left!=null)
q.add(cur.left);
if(cur.right!=null)
q.add(cur.right);
}
ans.add(max);
bfs();
}边栏推荐
- What does virtualization mean? What technologies are included? What is the difference with private cloud?
- Is it safe to open a fund account? How to apply
- 【Flink】Flink 批处理模式Map端数据聚合 NormalizedKeySorter
- 2022.6.20-----leetcode. seven hundred and fifteen
- Deletelater Usage Summary in QT
- EF core Basics
- Uni app custom navigation bar component
- Alibaba cloud function computing service one click to build Z-blog personal blog
- Binary search
- Camera-memory内存泄漏分析(三)
猜你喜欢

使用SOAPUI访问对应的esb工程

progress bar

Solve the problem that the uniapp plug-in Robin editor reports an error when setting the font color and background color

云计算基础-0

Uni app swiper rotation chart (full screen / card)

Request object, send request

MySQL development environment

MySQL高級篇第一章(linux下安裝MySQL)【下】

【LOJ#6718】九个太阳「弱」化版(循环卷积,任意模数NTT)

ABP framework
随机推荐
Andorid hide the title bar of the system
用eclipse连mysql数据库出错然后出现图中的话是咋回事呀
Kotlin quick start
2022.6.25-----leetcode. Sword finger offer 091
等保备案是等保测评吗?两者是什么关系?
高性能算力中心 — RoCE — Overview
Classic model - Nin & googlenet
ABP framework Practice Series (III) - domain layer in depth
云计算基础-0
Slide the menu of uni app custom components left and right and click switch to select and display in the middle
Click event
xml 解析bean工具类
MySQL高级篇第一章(linux下安装MySQL)【下】
C # knowledge structure
MySQL stored procedure
An error occurred using the connection to database 'on server' 10.28.253.2‘
Gradient
redux-thunk 简单案例,优缺点和思考
【Flink】Flink 批处理模式Map端数据聚合 NormalizedKeySorter
js实现文字跑马灯效果