当前位置:网站首页>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;
}边栏推荐
- C语言学习概览(三)
- 我三本学历,五面阿里,被面试官“供”着出来了,拿了33*15的Offer
- 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
- 基于tika实现对文件类型进行判断
- flink sql-client,怎么处理源端与目标增加端,sql-client包括映射表与JOB如
- Electromagnetic compatibility introductory tutorial (6) test project
- 【HDLBits 刷题】Circuits(1)Combinational Logic
- NIO programming
- 套接字选项
猜你喜欢

特殊的日子,值得纪念

特别数的和

How to generate and configure public key certificate in Alipay

Offer刷题——1

MATLAB program design and application of MATLAB 2.5

The use of Golang: go template engine

类似 MS Project 的项目管理工具有哪些

【HDLBits 刷题】Circuits(1)Combinational Logic

VSCode插件推荐(Rust环境)

Image lossless compression software which works: try completely free JPG - C image batch finishing compression reduces weight tools | latest JPG batch dressing tools download
随机推荐
MATLAB程序设计与应用 2.5 MATLAB运算
05-SDRAM:仲裁
13 - JUC CountDownLatch concurrent programming
R语言使用tidyquant包的tq_transmute函数计算持有某只股票的天、月、周收益率、ggplot2使用条形图可视化股票月收益率数据、使用百分比显示Y轴坐标数据、使用不同的色彩表征正负收益率
LeetCode240+312+394
【ASWC Arxml结构分解】-7-Explicit(显式)和Implicit(隐式) Sender-Receiver communication描述差异
Offer刷题——1
POJ2031空间站题解
Datagrip error "The specified database userpassword combination is rejected..."Solutions
HPC系统简介
Centos install php7.4, build hyperf, forward RDS
app 自动化 通过工具查看app 元素 (三)
LabVIEW中局部变量和全局变量的分配
22牛客多校1 C.Grab the Seat (几何 + 暴力)
第02章 MySQL的数据目录【1.MySQL架构篇】【MySQL高级】
USB 协议 (二) 术语
sum of special numbers
VoLTE基础学习系列 | 企业语音网简述
【一句话攻略】彻底理解JS中的回调(Callback)函数
pytest interface automation testing framework | skip test classes