当前位置:网站首页>JS 力扣刷题 102. 二叉树的层序遍历
JS 力扣刷题 102. 二叉树的层序遍历
2022-04-23 13:54:00 【Candy_Rainbow_】
var levelOrder = function(root) {
let rear = [];//遍历的队列
let answers = [];//二维数组
if(!root)return answers;//特殊情况
rear.push(root);//根节点入队
while(rear.length > 0){
let answer = [];//一层一层遍历
let len = rear.length;//队列长度会变,记录以下
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://blog.csdn.net/Candy_Rainbow_/article/details/124352249
边栏推荐
- Detailed explanation of redis (Basic + data type + transaction + persistence + publish and subscribe + master-slave replication + sentinel + cache penetration, breakdown and avalanche)
- Test on the time required for Oracle to delete data with delete
- Window function row commonly used for fusion and de duplication_ number
- Failure to connect due to improper parameter setting of Rac environment database node. Troubleshooting
- MySQL [read / write lock + table lock + row lock + mvcc]
- Express②(路由)
- Oracle index status query and index reconstruction
- Function executes only the once function for the first time
- At the same time, the problems of height collapse and outer margin overlap are solved
- Lenovo Saver y9000x 2020
猜你喜欢
MySQL [acid + isolation level + redo log + undo log]
Reading notes: meta matrix factorization for federated rating predictions
[machine learning] Note 4. KNN + cross validation
2022年江西最新建筑八大员(质量员)模拟考试题库及答案解析
Express②(路由)
MySQL [SQL performance analysis + SQL tuning]
3300万IOPS、39微秒延迟、碳足迹认证,谁在认真搞事情?
Solution of discarding evaluate function in surprise Library
PG SQL intercepts the string to the specified character position
UML统一建模语言
随机推荐
AtCoder Beginner Contest 248C Dice Sum (生成函数)
The difference between is and as in Oracle stored procedure
Oracle kills the executing SQL
Oracle and MySQL batch query all table names and table name comments under users
Ora-600 encountered in Oracle environment [qkacon: fjswrwo]
Oracle view related
Get the attribute value difference between two different objects with reflection and annotation
Android interview theme collection
Reading notes: meta matrix factorization for federated rating predictions
低频量化之明日涨停预测
Building MySQL environment under Ubuntu & getting to know SQL
Dolphin scheduler integrates Flink task pit records
MySQL [SQL performance analysis + SQL tuning]
商家案例 | 运动健康APP用户促活怎么做?做好这几点足矣
freeCodeCamp----time_ Calculator exercise
Modification of table fields by Oracle
Modify the Jupiter notebook style
What is the difference between blue-green publishing, rolling publishing and gray publishing?
【项目】小帽外卖(八)
Leetcode? The first common node of two linked lists