diameter
to 0 to keep track of the maximum diameter.longestPath
that computes the height of the subtree rooted at the given node and updates the diameter
.None
, return 0.diameter
with the sum of the longest paths from the left and right if it's greater than the current diameter
.longestPath
with the root of the tree.diameter
.