48. Diameter of Binary Tree

The diameter is the number of edges on the longest path between any two nodes. The path does not have to pass through the root.

Example 1

Input: root = [1,2,3,4,5]
Output: 3
Explanation: Path 4 → 2 → 1 → 3 has 3 edges.

Example 2

Input: root = [1,2,null,3,4,5,null,null,6]
Output: 4
Hint 1

Every path has a highest node where it “bends”. Its length there is leftHeight + rightHeight.

TreeDFS