
这题有一点像之前做过的longest path题的变形。
使用一个Global Variable 来track longest among tree.
比较Tricky的是ans = Math.max(ans, arrLeft+arrRight);
和return Math.max(arrowLeft, arrowRight)
longest seen so far 存在ans里,我们还是要返回一个arrowLeft or arrowRight so that its parent node
might be able to merge it to get a even longer path.

网友评论