当前位置:网站首页>JS force deduction brush question 103 Zigzag sequence traversal of binary tree
JS force deduction brush question 103 Zigzag sequence traversal of binary tree
2022-04-23 13:56:00 【Candy_ Rainbow_】
var zigzagLevelOrder = function(root) {
let rear = [];// Traversal queue
let answers = [];// Two dimensional array
if(!root)return answers;// A special case
rear.push(root);// Root in line
let flagStack = 1;// Single layer from left to right ( queue ) Double deck from right to left ( Stack )
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();
if(flagStack % 2 == 1)// Single layer from left to right ( queue )
answer.push(tmp.val);
else// Double deck from right to left ( Stack )
answer.unshift(tmp.val);
if(tmp.left)rear.push(tmp.left);
if(tmp.right)rear.push(tmp.right);
}
answers.push(answer);
flagStack++;
}
return answers;
};
版权声明
本文为[Candy_ Rainbow_]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231353588755.html
边栏推荐
- Express中间件③(自定义中间件)
- Oracle and MySQL batch query all table names and table name comments under users
- JS 烧脑面试题大赏
- Using Jupiter notebook in virtual environment
- Technologie zéro copie
- Oracle job scheduled task usage details
- [code analysis (1)] communication efficient learning of deep networks from decentralized data
- 函数只执行第一次的执行一次 once函数
- The query did not generate a result set exception resolution when the dolphin scheduler schedules the SQL task to create a table
- OSS cloud storage management practice (polite experience)
猜你喜欢

The art of automation

Quartus Prime硬件实验开发(DE2-115板)实验二功能可调综合计时器设计
![[VMware] address of VMware Tools](/img/0e/13f263bd69c8224f7c755258d94777.png)
[VMware] address of VMware Tools

freeCodeCamp----arithmetic_ Arranger exercise

初探 Lambda Powertools TypeScript
![Three characteristics of volatile keyword [data visibility, prohibition of instruction rearrangement and no guarantee of operation atomicity]](/img/ec/b1e99e0f6e7d1ef1ce70eb92ba52c6.png)
Three characteristics of volatile keyword [data visibility, prohibition of instruction rearrangement and no guarantee of operation atomicity]

SQL learning window function

Oracle告警日志alert.log和跟踪trace文件中文乱码显示

【vmware】vmware tools 地址

crontab定时任务输出产生大量邮件耗尽文件系统inode问题处理
随机推荐
Core concepts of microservice architecture
Express ② (routing)
Oracle creates tablespaces and modifies user default tablespaces
freeCodeCamp----arithmetic_ Arranger exercise
What is the difference between blue-green publishing, rolling publishing and gray publishing?
Apache seatunnel 2.1.0 deployment and stepping on the pit
JUC interview questions about synchronized, ThreadLocal, thread pool and atomic atomic classes
Decentralized Collaborative Learning Framework for Next POI Recommendation
Storage scheme of video viewing records of users in station B
Ora-16047 of a DG environment: dgid mismatch between destination setting and target database troubleshooting and listening vncr features
Oracle RAC database instance startup exception analysis IPC send timeout
Oracle and MySQL batch query all table names and table name comments under users
Dynamic subset division problem
Oracle defines self incrementing primary keys through triggers and sequences, and sets a scheduled task to insert a piece of data into the target table every second
Oracle generates millisecond timestamps
freeCodeCamp----time_ Calculator exercise
[code analysis (2)] communication efficient learning of deep networks from decentralized data
Failure to connect due to improper parameter setting of Rac environment database node. Troubleshooting
SQL learning | complex query
Window analysis function last_ VALUE,FIRST_ VALUE,lag,lead