当前位置:网站首页>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;
}边栏推荐
猜你喜欢

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

小程序更多的手势事件(左右滑动、放大缩小、双击、长按)

SaaS安全认证综合指南

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

数据分析6

研发过程中的文档管理与工具

22牛客多校1 C.Grab the Seat (几何 + 暴力)

特别数的和

插入排序—直接插入排序和希尔排序
![[Tear AHB-APB Bridge by hand]~ Why aren't the lower two bits of the AHB address bus used to represent the address?](/img/fb/c95c5857024db001638cd484c5e78f.png)
[Tear AHB-APB Bridge by hand]~ Why aren't the lower two bits of the AHB address bus used to represent the address?
随机推荐
Shell执行SQL发邮件
VoLTE基础学习系列 | 企业语音网简述
国内外最顶级的8大plm项目管理系统
华为深度学习课程第九章——卷积神经网络以及案例实践
Create, modify and delete tables
The socket option
app 自动化 打开app (二)
Golang:go连接和使用mysql
Offer刷题——1
Golang: go get url and form attribute value
七夕来袭——属于程序员的浪漫
Chapters 6 and 7 of Huawei Deep Learning Course
How to use Photoshop to composite star trail photos, post-processing method of night sky star trail photos
Pytest | skip module interface test automation framework
Classwork (7) - #598. remainder operation (mod)
pytest接口自动化测试框架 | 集成Allure测试报告
MATLAB program design and application of MATLAB 2.5
rhcsa 第三次
What do the values 1, 2, and 3 in nodetype mean?
22 Niu Ke Duo School 1 I. Chiitoitsu (Probability dp)