当前位置:网站首页>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
边栏推荐
- [code analysis (4)] communication efficient learning of deep networks from decentralized data
- Express middleware ③ (custom Middleware)
- Operations related to Oracle partition
- 函数只执行第一次的执行一次 once函数
- Reading notes: Secure federated matrix factorization
- Problems encountered in the project (V) understanding of operating excel interface poi
- Jiannanchun understood the word game
- redis如何解决缓存雪崩、缓存击穿和缓存穿透问题
- 自动化的艺术
- Detailed explanation of redis (Basic + data type + transaction + persistence + publish and subscribe + master-slave replication + sentinel + cache penetration, breakdown and avalanche)
猜你喜欢
Information: 2021 / 9 / 29 10:01 - build completed with 1 error and 0 warnings in 11S 30ms error exception handling
Window analysis function last_ VALUE,FIRST_ VALUE,lag,lead
Express②(路由)
OSS cloud storage management practice (polite experience)
Port occupied 1
SQL learning window function
Dolphin scheduler integrates Flink task pit records
elmo(BiLSTM-CRF+elmo)(Conll-2003 命名实体识别NER)
freeCodeCamp----arithmetic_ Arranger exercise
JS brain burning interview question reward
随机推荐
19c RAC steps for modifying VIP and scanip - same network segment
Two ways to deal with conflicting data in MySQL and PG Libraries
Using Jupiter notebook in virtual environment
[code analysis (7)] communication efficient learning of deep networks from decentralized data
UML Unified Modeling Language
Dolphin scheduler configuring dataX pit records
FDFS start
Leetcode brush question 897 incremental sequential search tree
RAC environment alert log error drop transient type: systp2jw0acnaurdgu1sbqmbryw = = troubleshooting
解决方案架构师的小锦囊 - 架构图的 5 种类型
ACFs file system creation, expansion, reduction and other configuration steps
Window function row commonly used for fusion and de duplication_ number
淘宝发布宝贝提示“您的消保保证金额度不足,已启动到期保障”
Troubleshooting of expdp export error when Oracle table has logical bad blocks
Dolphin scheduler scheduling spark task stepping record
OSS cloud storage management practice (polite experience)
第十五章 软件工程新技术
SQL learning window function
Oracle database recovery data
Tensorflow & pytorch common error reporting