Given the root of a binary tree, return the maximum length of a ZigZag path contained in the tree.
A ZigZag path is defined as follows:
Start at any node in the tree and select an initial direction (left or right).
If the current direction is right, move to the right child of the current node; otherwise, move to the left child.
Alternate the direction after each step (switch from right to left, or left to right).
Repeat this movement until you can no longer proceed.
The length of a ZigZag path is defined as the number of edges traversed (a path with a single node has a length of
Constraints:
The number of nodes in the tree is in the range
Node.val
Given the root of a binary tree, return the maximum length of a ZigZag path contained in the tree.
A ZigZag path is defined as follows:
Start at any node in the tree and select an initial direction (left or right).
If the current direction is right, move to the right child of the current node; otherwise, move to the left child.
Alternate the direction after each step (switch from right to left, or left to right).
Repeat this movement until you can no longer proceed.
The length of a ZigZag path is defined as the number of edges traversed (a path with a single node has a length of
Constraints:
The number of nodes in the tree is in the range
Node.val