The diameter through a node equals left height + right height.
DFS returns subtree height. While computing heights, update a global best with leftHeight + rightHeight.
Every longest path has a highest (LCA) node; evaluating lh+rh at each node considers all possible diameters.
The diameter through a node equals left height + right height.
DFS returns subtree height. While computing heights, update a global best with leftHeight + rightHeight.
Every longest path has a highest (LCA) node; evaluating lh+rh at each node considers all possible diameters.