当前位置:网站首页>2022.7.31-----leetcode.1161
2022.7.31-----leetcode.1161
2022-08-01 07:42:00 【路Lu727】
public int maxLevelSum(TreeNode root) {
Deque<TreeNode> q=new ArrayDeque<>();
q.add(root);
int layer=1;
int ans=0;
int max=Integer.MIN_VALUE;
while(!q.isEmpty()){
int size=q.size();
int sum=0;
for(int i=0;i<size;i++){
TreeNode n=q.poll();
if(n.left!=null)
q.add(n.left);
if(n.right!=null)
q.add(n.right);
sum+=n.val;
}
if(sum>max){
max=sum;
ans=layer;
}
layer++;
}
return ans;
}边栏推荐
猜你喜欢

最小生成树

app 自动化 打开app (二)

Data organization -- singly linked list of the linear table

小程序通过云函数操作数据库【使用get取数据库】

我三本学历,五面阿里,被面试官“供”着出来了,拿了33*15的Offer

How to use Photoshop to composite star trail photos, post-processing method of night sky star trail photos

【手撕AHB-APB Bridge】~ AHB地址总线的低两位为什么不用来表示地址呢?

【MySQL】操作表DML相关语句

拳头游戏免版权音乐下载,英雄联盟无版权音乐,可用于视频创作、直播

"By sharing" northwestern university life service | | bytes a second interview on three sides by HR
随机推荐
my creative day
Do I need to introduce any dependencies to write data to clickhouse using flinksql?
类似 MS Project 的项目管理工具有哪些
小程序更多的手势事件(左右滑动、放大缩小、双击、长按)
Delphi MDI appliction 文档最大化显示、去掉最大化最小化等按钮
05-SDRAM:仲裁
配置我的kitty
rhcsa 第四天
R语言使用tidyquant包的tq_transmute函数计算持有某只股票的天、月、周收益率、ggplot2使用条形图可视化股票月收益率数据、使用百分比显示Y轴坐标数据、使用不同的色彩表征正负收益率
案例实践 --- Resnet经典卷积神经网络(Mindspore)
Centos install php7.4, build hyperf, forward RDS
pytest interface automation testing framework | single/multiple parameters
最小生成树
pytest接口自动化测试框架 | parametrize源码解析
零代码网站开发利器:WordPress
LeetCode240+312+394
Self-made a remote control software - VeryControl
22牛客多校1 C.Grab the Seat (几何 + 暴力)
R语言使用gt包和gtExtras包优雅地、漂亮地显示表格数据:gtExtras包的pad_fn函数与gt::fmt函数一起用于填充包含数值的特定列、对数据列的数值进行十进制对齐(从小数点对齐)
[Tear AHB-APB Bridge by hand]~ Why aren't the lower two bits of the AHB address bus used to represent the address?