Medium · Trees
Get diameter
Given the root of a binary tree, return its diameter: the number of edges on the longest path between any two nodes (0 for an empty or single-node tree).
Examples
Example 1
[1,2,3,4,5]Output: diameter 3
Example 2
{
"tree": [1, 2, null, 3]
}Output: diameter 2
Rebuild it in the studio
Open every published interview problem, solution, scene, and memory room free, with no account.