Leetcode Problem 2415. Reverse Odd Levels of Binary Tree
2415. Reverse Odd Levels of Binary Tree
Leetcode Solutions
BFS Level Order Traversal with Reversal on Odd Levels
Initialize a queue and add the root node to it.
Initialize a variable to keep track of the current level, starting at 0.
While the queue is not empty:
a. Record the size of the queue, which represents the number of nodes at the current level.
b. If the current level is odd, create a temporary list to store the node values.
c. For each node at the current level:
i. Pop the node from the queue.
ii. If the level is odd, add the node's value to the temporary list.
iii. Add the node's left and right children to the queue if they exist.
d. If the level is odd, reverse the temporary list and reassign the values to the nodes at the current level.
e. Increment the level counter.