Diameter of Binary Tree
Return the largest number of edges in any path between two nodes of a binary tree. The path need not pass through the root.
Example 1
root = [1,2,3,4,5]3Explanation
4->2->1->3 has three edges; diameter counts edges rather than nodes.
Example 2
root = [1]0Explanation
A single node has no edge, giving diameter zero.
Example 3
root = []0Explanation
An empty tree has no path edge to count.
Constraints
- 0 <= number of nodes <= 10000
- Trees are breadth-first arrays with null holes
Function contract
diameterOfBinaryTreeArguments: treeSolutionRuns on your device
Loading draft…
Run: 3 examples; Submit: 34 cases, on your device.
[1,2,3,4,5]