当前位置:网站首页>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;
}边栏推荐
- NIO programming
- 22牛客多校1 I. Chiitoitsu (概率dp)
- Delphi MDI appliction 文档最大化显示、去掉最大化最小化等按钮
- Json对象和Json字符串的区别
- Data organization -- singly linked list of the linear table
- 22牛客多校1 J.Serval and Essay (启发式合并)
- Golang: go to connect and use mysql
- How to use Photoshop to composite star trail photos, post-processing method of night sky star trail photos
- special day to remember
- 力扣每日一题-第44天-290. 单词规律
猜你喜欢

Fist game copyright-free music download, League of Legends copyright-free music, can be used for video creation, live broadcast

Vim简介

图片无损压缩软件哪个好用:试试完全免费的JPG-C 图片批量修整压缩减肥工具吧 | 最新jpg批量修整工具下载

【HDLBits 刷题】Circuits(1)Combinational Logic

小程序全面屏手势配置案例

"By sharing" northwestern university life service | | bytes a second interview on three sides by HR

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

Upgrade to heavyweight lock, lock reentrancy will lead to lock release?

The log causes these pits in the thread block, you have to prevent

日志导致线程Block的这些坑,你不得不防
随机推荐
Delphi MDI appliction documents maximize display, remove buttons such as maximize and minimize
Offer brush questions - 1
rhcsa 第三次
华为深度学习课程第九章——卷积神经网络以及案例实践
自制一款远程控制软件——VeryControl
Golang:go连接和使用mysql
国内外最顶级的8大plm项目管理系统
Pytest | skip module interface test automation framework
Electromagnetic compatibility introductory tutorial (6) test project
pytest接口自动化测试框架 | 单个/多个参数
pytest interface automation testing framework | pass in parameter values in the form of function return values
XX市消防救援指挥中心实战指挥平台多链路聚合解决方案实例
LeetCode240+312+394
Create, modify and delete tables
LabVIEW RT中的用户界面更新速度
零代码网站开发利器:WordPress
POJ1287联网题解
Flink SQL - client, how to deal with the source side and to increase the target, the SQL - client including mapping table and the JOB such as
特殊的日子,值得纪念
企业数据虚拟化综合指南