Leetcode Problem 102. Binary Tree Level Order Traversal
102. Binary Tree Level Order Traversal
Leetcode Solutions
Breadth-First Search (BFS) Iterative Approach
Check if the root is null, return an empty list if true.
Initialize a queue to hold nodes at the current level and add the root node to it.
Initialize an output list to hold the level order traversal result.
While the queue is not empty:
a. Create a temporary list to store the values of nodes at the current level.
b. Record the number of nodes at the current level (queue size).
c. Iterate over the number of nodes at the current level:
i. Dequeue the front node from the queue.
ii. Add the node's value to the temporary list.
iii. Enqueue the node's left and right children if they are not null.
d. Add the temporary list to the output list.