root of a binary tree. Walk it level by level like a snake: the root's level is read left to right, the next one right to left, the next one left to right again, and so on, alternating the direction.
Return the list of levels from top to bottom, each level being the list of values in reading order. For an empty tree, return an empty list.root=tree_node([8, 3, 10, 1, 6, None, 14]) → [[8], [10, 3], [1, 6, 14]]
Level 0 is read left to right: 8. Level 1 right to left: 10, 3. Level 2 left to right again: 1, 6, 14.
root=tree_node([1, 2, None, 3, 4]) → [[1], [2], [3, 4]]
Level 1 has a single node, so the direction does not matter; level 2 is left to right again: 3, 4.
root=tree_node([]) → []
An empty tree gives an empty list.
Node.val ≤ 1000root=tree_node([8, 3, 10, 1, 6, None, 14])
[[8], [10, 3], [1, 6, 14]]
Run checks the first 3 tests in your browser. Submit checks all 87 tests on the server, hidden ones included.