美文网首页
Longest Univalue path

Longest Univalue path

作者: 98Future | 来源:发表于2017-11-10 12:02 被阅读0次

这题有一点像之前做过的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.

相关文章

网友评论

      本文标题:Longest Univalue path

      本文链接:https://www.haomeiwen.com/subject/czaumxtx.html