当前位置:网站首页>JS force deduction brush question 102 Sequence traversal of binary tree
JS force deduction brush question 102 Sequence traversal of binary tree
2022-04-23 13:56:00 【Candy_ Rainbow_】
var levelOrder = function(root) {
let rear = [];// Traversal queue
let answers = [];// Two dimensional array
if(!root)return answers;// A special case
rear.push(root);// Root in line
while(rear.length > 0){
let answer = [];// Traversal layer by layer
let len = rear.length;// The queue length will change , Record the following
for(let i = 0; i < len; i++){
let tmp = rear.shift();
answer.push(tmp.val);
if(tmp.left)rear.push(tmp.left);
if(tmp.right)rear.push(tmp.right);
}
answers.push(answer);
}
return answers;
};
版权声明
本文为[Candy_ Rainbow_]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231353588806.html
边栏推荐
- Influence of openssh version on SSH mutual trust creation in RAC environment
- 美联储数字货币最新进展
- 第一章 电商秒杀商品回顾
- Move blog to CSDN
- Oracle lock table query and unlocking method
- China creates vast research infrastructure to support ambitious climate goals
- Multithreading
- Apache Atlas Compilation and installation records
- 商家案例 | 运动健康APP用户促活怎么做?做好这几点足矣
- Detailed explanation and usage of with function in SQL
猜你喜欢
Handling of high usage of Oracle undo
2021年秋招,薪资排行NO
记录一个奇怪的bug:缓存组件跳转之后出现组件复制
Dolphin scheduler source package Src tar. GZ decompression problem
SQL learning | complex query
Quartus Prime硬件实验开发(DE2-115板)实验二功能可调综合计时器设计
专题测试05·二重积分【李艳芳全程班】
大专的我,闭关苦学 56 天,含泪拿下阿里 offer,五轮面试,六个小时灵魂拷问
What is the difference between blue-green publishing, rolling publishing and gray publishing?
Lenovo Saver y9000x 2020
随机推荐
Dolphin scheduler source package Src tar. GZ decompression problem
Function executes only the once function for the first time
Reading notes: meta matrix factorization for federated rating predictions
Postman reference summary
Failure to connect due to improper parameter setting of Rac environment database node. Troubleshooting
Quartus Prime硬件实验开发(DE2-115板)实验二功能可调综合计时器设计
Analysis of redo log generated by select command
Oracle告警日志alert.log和跟踪trace文件中文乱码显示
Parameter comparison of several e-book readers
L2-024 部落 (25 分)
Oracle alarm log alert Chinese trace and trace files
[code analysis (4)] communication efficient learning of deep networks from decentralized data
leetcode--380.O(1) 时间插入、删除和获取随机元素
Three characteristics of volatile keyword [data visibility, prohibition of instruction rearrangement and no guarantee of operation atomicity]
Jiannanchun understood the word game
MySQL [read / write lock + table lock + row lock + mvcc]
China creates vast research infrastructure to support ambitious climate goals
Atcoder beginer contest 248c dice sum (generating function)
PG library checks the name
Dolphin scheduler integrates Flink task pit records