当前位置:网站首页>Hierarchical output binary tree
Hierarchical output binary tree
2022-04-23 08:05:00 【Pen drawing Acacia】
var levelOrder = function(root) {
if (!root) return [];
let queue = [];
let res = [];
let level = 0;
queue.push(root);
let temp;
while (queue.length) {
res.push([]);
let size = queue.length; // Pay attention to the :
size--; // It is a very important skill in hierarchy traversal
while (size--) {
// Out of the team
let front = queue.shift();
res[level].push(front.val); // The team
if (front.left) queue.push(front.left);
if (front.right) queue.push(front.right);
}
level++;
}
return res;
};
版权声明
本文为[Pen drawing Acacia]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230624332609.html
边栏推荐
- 输入 “ net start mysql ”,出现 “ 发生系统错误 5。 拒绝访问 ” 。问题详解
- RGB color to hex and unit conversion
- LeetCoed18. 四数之和
- Chapter IV intangible assets
- Internal network security attack and defense: a practical guide to penetration testing (5): analysis and defense of horizontal movement in the domain
- Three minutes to teach you to use Houdini fluid > > to solve particle fluid droplets
- Implementation of new
- 【编程实践/嵌入式比赛】嵌入式比赛学习记录(一):TCP服务器和web界面的建立
- sentinel集成nacos动态更新数据原理
- SAP tr manual import system operation manual
猜你喜欢
惨了,搞坏了领导的机密文件,吐血分享备份文件的代码技巧
Concours de compétences en informatique en nuage - - première partie de l'environnement cloud privé openstack
vivo,硬件安全的爱与雷霆
内网渗透系列:内网隧道之icmpsh
内网渗透系列:内网隧道之dnscat2
How does feign integrate hystrix
CTF attack and defense world brush questions 51-
Export all SVG files in the specified path into pictures in PNG format (thumbnail or original size)
Mysql database backup and recovery under Linux (full + incremental)
Research on software security based on NLP (I)
随机推荐
SAP self created table log function is enabled
Alibaba sentinel learning QA
内网渗透系列:内网隧道之pingtunnel
Intranet penetration series: icmpsh of Intranet tunnel
SAP tr manual import system operation manual
Using lambda expression to solve the problem of C file name sorting (whether it is 100 or 11)
Three minutes to teach you to use Houdini fluid > > to solve particle fluid droplets
内网渗透系列:内网隧道之icmp_tran
SAP sto with billing process and configuration
How does feign integrate hystrix
内网渗透系列:内网隧道之icmptunnel(jamesbarlow师傅的)
Buuctf misc brush questions
Reverse linked list exercise
CTF攻防世界刷题51-
1+x云计算中级--脚本搭建读写分离
Ignis公链的NFT生态发展:Unicorn.art的捐赠开发之路
面试学习路线
Intranet security attack and defense: a practical guide to penetration testing (6): domain controller security
Chapter V investment real estate
KVM安装部署