【LeetCode 0102】【BSF】二叉树的层级遍历

  1. Binary Tree Level Order Traversal

Given the root of a binary tree, return the level order traversal of its nodes' values. (i.e., from left to right, level by level).

Example 1:

复制代码
**Input:** root = [3,9,20,null,null,15,7]
**Output:** [[3],[9,20],[15,7]]

Example 2:

复制代码
**Input:** root = [1]
**Output:** [[1]]

Example 3:

复制代码
**Input:** root = []
**Output:** []

Constraints:

  • The number of nodes in the tree is in the range [0, 2000].
  • -1000 <= Node.val <= 1000
Idea
text 复制代码
借助于栈,实现BSF
javascript 复制代码
相关推荐
geovindu18 分钟前
go: Recursion Algorithm
开发语言·后端·算法·golang·递归算法
Shadow(⊙o⊙)1 小时前
日志与线程池
linux·c++·算法
冷小鱼1 小时前
AI Agent 的核心算法:多智能体协作(Multi-Agent Systems)
前端·人工智能·算法·multi-agent·多智能体协作·systems
QN1幻化引擎1 小时前
# DalinX V8 灵鉴 V2:12维意识评测框架 —— 从 Tononi IIT 到 Friston FEP 的理论统一
数据库·人工智能·算法·机器学习·数据挖掘·agi
牧以南歌〆1 小时前
数据结构<一>顺序表
c语言·数据结构·算法
江畔柳前堤1 小时前
Go04-控制结构
大数据·人工智能·面试·职场和发展·go·业界资讯
Fairy要carry2 小时前
面试-训练显存占用估计
算法
触底反弹2 小时前
💥 暴力解 LeetCode 导致 OOM:10000 行数据撑爆 V8 堆内存的完整排查
javascript·算法·面试
cheems95272 小时前
[算法手记]二叉树中序,层序遍历,统计树高
算法