longestPath(TreeNode node)
that returns an array [inr, dcr]
.[0, 0]
.longestPath
for the left and right children of the current node.dcr
as left_dcr + 1
.inr
as left_inr + 1
.inr
and dcr
.max(maxval, inr + dcr - 1)
.[inr, dcr]
for the current node.