【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 复制代码
相关推荐
程序猿阿森2 分钟前
【机器学习实战】朴素贝叶斯算法详解:从概率基础到商品评论情感分析
算法·机器学习·概率论
xxwl58513 分钟前
区域赛算法模版第五章---数学与数论
c++·笔记·算法
看浪的路人37 分钟前
第6讲:Agent 安全体系——Prompt 注入防御、工具调用审计与输出合规
人工智能·算法
局部有解1 小时前
LeetCode Hot100 438 找到字符串中所有字母异位词
c++·算法·leetcode
垆边人似月.1 小时前
移动长度 k 子串使字符串变成回文
数据结构·算法
pride.li1 小时前
第12章 Python 教程-流程控制:循环结构
linux·服务器·python·算法
海绵宝宝转agent2 小时前
2026-10-16 4算法+1面经
算法
小poop2 小时前
基础排序算法详解——插入、选择与交换排序
算法·排序算法
青蓝智慧马老师2 小时前
想学数据分析但零基础,正确顺序不是先学 Python
大数据·人工智能·算法
jeo陽2 小时前
05-数组与冒泡排序:第一个数据结构与经典算法
c语言·数据结构·算法