Leetcode Problem 103. Binary Tree Zigzag Level Order Traversal
103. Binary Tree Zigzag Level Order Traversal
Leetcode Solutions
BFS with Zigzag Order Traversal
Check if the root is null. If so, return an empty list.
Initialize a deque to store nodes of the current level.
Initialize a list to store the final zigzag order traversal.
Use a variable to keep track of the current level and whether to traverse from left to right or right to left.
Perform a BFS traversal using a queue. At each level:
a. Clear the current level deque.
b. Determine the direction of traversal based on the current level.
c. For each node at the current level, add its value to the deque in the appropriate direction.
d. Add the deque to the result list after processing all nodes at the level.