Given the root of a binary tree, compute and return a list of integers representing the zigzag level sum for each level of the tree.
The tree levels are root is at level
If the level number is odd, iterate through the nodes from left to right. For each node, if it has a left child, add its value to the level sum. If a node does not have a left child, stop processing that level immediately.
If the level number is even, iterate through the nodes from right to left. For each node, if it has a right child, add its value to the level sum. If a node does not have a right child, stop processing that level immediately.
Return a list containing the resulting sum for each level from level
Constraints:
The number of nodes in the tree is in the range
Node.val
Given the root of a binary tree, compute and return a list of integers representing the zigzag level sum for each level of the tree.
The tree levels are root is at level
If the level number is odd, iterate through the nodes from left to right. For each node, if it has a left child, add its value to the level sum. If a node does not have a left child, stop processing that level immediately.
If the level number is even, iterate through the nodes from right to left. For each node, if it has a right child, add its value to the level sum. If a node does not have a right child, stop processing that level immediately.
Return a list containing the resulting sum for each level from level
Constraints:
The number of nodes in the tree is in the range
Node.val