Practice/Meta/Leetcode 102. Binary Tree Level Order Traversal
CodingMust
Given the root of a binary tree, return a list of lists containing the node values organized by their depth level. Each inner list should contain all node values at that particular depth, ordered from left to right. If the tree is empty, return an empty list.
This traversal pattern visits all nodes at depth 0, then all nodes at depth 1, and so on, processing nodes at each level from left to right before moving to the next level.
Example 1:
Input: root = [3,9,20,null,null,15,7] 3 / \ 9 20 / \ 15 7 Output: [[3], [9, 20], [15, 7]] Explanation: The root forms the first level, its children form the second level, and the leaf nodes form the third level.
Example 2:
Input: root = [1] Output: [[1]] Explanation: A single node tree has only one level.
Example 3:
Input: root = [] Output: [] Explanation: An empty tree has no levels to traverse.
Example 4:
Input: root = [1,2,3,4,5,6,7] 1 / \ 2 3 / \ / \ 4 5 6 7 Output: [[1], [2, 3], [4, 5, 6, 7]] Explanation: Three levels with increasing number of nodes per level.