Given the root of a binary tree, return the length of the diameter of the tree.
The diameter is the length of the longest path between any two nodes, and that path may or may not pass through the root.
Reason about the value returned from each subtree and the state passed down from ancestors. Empty children and single-node trees should be handled naturally.
Examples
Input: root = [1,2,3,4,5] Output: 3
Input: root = [1,2] Output: 1
Constraints
- The number of nodes is in the range [1, 10,000].
- -100 <= Node.val <= 100