当前位置:网站首页>2022.6.24-----leetcode.515
2022.6.24-----leetcode.515
2022-06-26 03:16:00 【路Lu727】
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;
}
//按层 层序遍历
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();
}边栏推荐
- Good news | congratulations on the addition of 5 new committers in Apache linkage (incubating) community
- kitti2bag 安装出现的各种错误
- Add an "open search description" to the site to adapt to the browser's "site search"“
- 双碳红利+基建大年 | 图扑深耕水利水电绿色智能装备领域
- Cultivate children's creativity under the concept of project steam Education
- 云计算基础-0
- 上传文件/文本/图片,盒子阴影
- MySQL增删查改(初阶)
- MySQL开发环境
- Cliquez sur le bouton action de la liste pour passer à une autre page de menu et activer le menu correspondant
猜你喜欢

TiFlash 函数下推必知必会丨十分钟成为 TiFlash Contributor

项目部署遇到的问题-生产环境
![[paper notes] supersizing self supervision: learning to grasp from 50K tries and 700 robot hours](/img/fe/f8208747e03133f4a66e73598409d5.png)
[paper notes] supersizing self supervision: learning to grasp from 50K tries and 700 robot hours

MySQL增删查改(进阶)

MySQL addition, deletion, query and modification (primary level)

The "eye" of industrial robot -- machine vision

Xiaomi TV's web page and jewelry's web page

Multimedia elements, audio, video

请求对象,发送请求

progress bar
随机推荐
培育项目式Steam教育理念下的儿童创造力
Add an "open search description" to the site to adapt to the browser's "site search"“
MySQL高级部分( 四: 锁机制、SQL优化 )
[appium stepping pit] io appium. uiautomator2. common. exceptions. InvalidArgumentException: ‘capabilities‘ are mand
USB peripheral driver - Enumeration
Is it safe for individuals to buy stocks with flush software? How to buy stocks
Upload file / text / picture, box shadow
Plug in installation and shortcut keys of jupyter notebook
Is it safe to open a fund account? How to apply
js实现文字跑马灯效果
Butterknife unbinder uses flashback in fragment and viewpager
少儿编程对国内传统学科的推进作用
[system architecture] - how to evaluate software architecture
“再谈”协议
XGBoost, lightGBM, CatBoost——尝试站在巨人的肩膀上
[hash table] a very simple zipper hash structure, so that the effect is too poor, there are too many conflicts, and the linked list is too long
Analysis of technological changes in social robots
点击事件
mysql存储过程
国信金太阳靠谱吗?开证券账户安全吗?