当前位置:网站首页>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();
}
边栏推荐
- jupyter notebook的插件安装以及快捷键
- Analysis of technological changes in social robots
- Request object, send request
- USB peripheral driver - Enumeration
- Digital twin intelligent water service, breaking through the development dilemma of sponge City
- Is it safe for Caicai securities to open an account in 2022?
- 上传文件/文本/图片,盒子阴影
- 等保备案是等保测评吗?两者是什么关系?
- 类图
- Qixia fire department carries out fire safety training on construction site
猜你喜欢
小米电视的网页和珠宝的网页
双碳红利+基建大年 | 图扑深耕水利水电绿色智能装备领域
MySQL development environment
How Inkscape converts PNG pictures to SVG pictures without distortion
上传文件/文本/图片,盒子阴影
Double carbon bonus + great year of infrastructure construction 𞓜 deep ploughing into the field of green intelligent equipment for water conservancy and hydropower
Partition, column, list
Analysis of the multiple evaluation system of children's programming
MySQL数据库基础
Upload file / text / picture, box shadow
随机推荐
类图
请求对象,发送请求
Analysis on the diversification of maker space mechanism construction
Is Guoxin golden sun reliable? Is it safe to open a securities account?
Android gap animation translate, scale, alpha, rotate
Worm copy construction operator overload
Good news | congratulations on the addition of 5 new committers in Apache linkage (incubating) community
How Inkscape converts PNG pictures to SVG pictures without distortion
路由跳转之点击列表的操作按钮,跳转至另一个菜单页面并激活相应的菜单
给网站添加“开放搜索描述“以适配浏览器的“站点搜索“
【读点论文】FBNetV3: Joint Architecture-Recipe Search using Predictor Pretraining 网络结构和超参数全当训练参数给训练了
progress bar
String到底能不能改变?
usb peripheral 驱动 - 枚举
redux-thunk 简单案例,优缺点和思考
培育项目式Steam教育理念下的儿童创造力
Popupwindow utility class
Various errors in kitti2bag installation
论文回顾:Unmixing-Based Soft Color Segmentation for Image Manipulation
工业机器人之“慧眼”——机器视觉