https://leetcode.com/problems/longest-zigzag-path-in-a-binary-tree/description/


class Solution {
int max = 0;
public int longestZigZag(TreeNode root) {
DFS(root.left, 1, "left");
DFS(root.right, 1, "right");
return max;
}
public void DFS(TreeNode node, int length, String direction) {
if(node == null) {
return;
}
max = Math.max(max, length);
if(direction.equals("right")) {
DFS(node.left, length + 1, "left");
DFS(node.right, 1, "right");
} else {
DFS(node.right, length + 1, "right");
DFS(node.left, 1, "left");
}
}
}