root of a binary tree. A path is a chain of nodes where neighbours are joined by an edge and no node appears twice. Its length is the number of edges it contains.
Return the length of the longest path between any two nodes of the tree. The path does not have to pass through the root.root=tree_node([6, 3, None, 8, 2, 7, None, None, 5]) → 4
The longest path is 7 → 8 → 3 → 2 → 5: it has 4 edges and does not go through the root 6 at all.
root=tree_node([1, -4, 9]) → 2
The path -4 → 1 → 9 has two edges.
root=tree_node([42]) → 0
A single node gives a path with no edges, length 0.
Node.val ≤ 100root=tree_node([6, 3, None, 8, 2, 7, None, None, 5])
4
Run checks the first 3 tests in your browser. Submit checks all 96 tests on the server, hidden ones included.