In the game of Snakes and Ladders, your piece moves left to right along one row, then right to left along the next row, and keeps switching. Read a binary tree the same way.
Take the tree root level by level, from the top down. Write the first level from left to right and the second level from right to left. Keep switching the direction on every level. Return the levels as a list of lists, from the top level to the bottom level.
Return a list of levels, and each level is a list of numbers.
How the judge passes the data
Examples
Example 1:
Input: root = [10,4,15,2,null,12,20]
Output: [[10],[15,4],[2,12,20]]
Explanation: The top level is [10]. The next level is read right to left, giving [15,4]. The last level is read left to right, giving [2,12,20].
Example 2:
Input: root = [9,5,12,3,7,11,14]
Output: [[9],[12,5],[3,7,11,14]]
Explanation: The three levels come out as [9], [12,5] and [3,7,11,14].
Example 3:
Input: root = [7,null,9,null,5]
Output: [[7],[9],[5]]
Explanation: The tree is a single chain. Every level has one value, so the reading direction changes nothing.