当前位置:网站首页>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;
}
边栏推荐
- Summary of test points about app updates in different ways
- 第02章 MySQL的数据目录【1.MySQL架构篇】【MySQL高级】
- Chapter 9 of Huawei Deep Learning Course - Convolutional Neural Network and Case Practice
- pytest接口自动化测试框架 | 使用函数返回值的形式传入参数值
- LeetCode 415:字符串相加
- Vim三种模式
- 类似 MS Project 的项目管理工具有哪些
- JVM: Runtime Data Area - PC Register (Program Counter)
- 电磁兼容简明教程(6)测试项目
- pytest接口自动化测试框架 | 集成Allure测试报告
猜你喜欢
随机推荐
特别数的和
How to use Photoshop to composite star trail photos, post-processing method of night sky star trail photos
GO错误处理方式
微信小程序请求封装
Monitor the width and height of the parent element, adapt to the size of the plug-in
zip打包目录所有文件(含隐藏文件/夹)
【南瓜书ML】(task4)神经网络中的数学推导(更新ing)
USB 协议 (二) 术语
图像基本操作的其他内容
最小生成树
关于App不同方式更新的测试点归纳
升级为重量级锁,锁重入会导致锁释放?
LeetCode240+312+394
GO error handling
旋度(7)连接失败localhost8080;连接拒绝了
Vim三种模式
【HDLBits 刷题】Circuits(1)Combinational Logic
Delphi MDI appliction 文档最大化显示、去掉最大化最小化等按钮
案例实践 --- Resnet经典卷积神经网络(Mindspore)
flink sql-client,怎么处理源端与目标增加端,sql-client包括映射表与JOB如