Redian新闻
>
Given a binary tree, find the maximum path sum
avatar
Given a binary tree, find the maximum path sum# JobHunting - 待字闺中
y*0
1
/**
Given a binary tree, find the maximum path sum.
The path may start and end at any node in the tree.
For example:
Given the below binary tree,
1
/ \
2 3
Return 6.
**/
OJ上面的题目。
给的例子,为啥是结果6,而不是4? 不是说path吗?
avatar
h*n
2
The path may start and end at any node in the tree.
avatar
s*u
3
这个path可以往上或者往下走。我也被坑到了。
avatar
r*n
4
path可以从一个叶子到根再到另一个叶子

【在 y*********0 的大作中提到】
: /**
: Given a binary tree, find the maximum path sum.
: The path may start and end at any node in the tree.
: For example:
: Given the below binary tree,
: 1
: / \
: 2 3
: Return 6.
: **/

avatar
S*6
5
任意两节点之间
avatar
l*1
6
容易想出一个lgN * N^2的笨算法,更好的想不出来了
avatar
l*1
7

其实是任意两个叶子节点之间

【在 S******6 的大作中提到】
: 任意两节点之间
avatar
z*8
8
不是吧, 如果叶子是负值呢?

【在 l****1 的大作中提到】
:
: 其实是任意两个叶子节点之间

avatar
l*1
9

那是,不过lgn * n^2也能解决负值的case。

【在 z*********8 的大作中提到】
: 不是吧, 如果叶子是负值呢?
相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。