###### 知之可否

Be yourself; everyone else is already taken.​

###### 124. Binary Tree Maximum Path Sum（难）

Given a binary tree, find the maximum path sum.

For this problem, a path is defined as any sequence of nodes from some starting node to any node in the tree along the parent-child connections. The path does not need to go through the root.

For example:
Given the below binary tree,

       1
/ \
2   3


Return 6.

# 编程之美: 求二叉树中节点的最大距离 很像

/**
* Definition for a binary tree node.
* struct TreeNode {
*     int val;
*     TreeNode *left;
*     TreeNode *right;
*     TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class Solution {
public:
int maxPathSum(TreeNode* root) {
if (root == NULL) return 0;
maxSum = INT_MIN;
maxPathDown(root);
return maxSum;
}

private:
int maxPathDown(TreeNode* root){
if (root == NULL) return 0;
int left = max(0,maxPathDown(root->left));
int right =max(0, maxPathDown(root->right));

maxSum = max(maxSum, left + right + root->val);

return max(left, right) + root->val;
}
int maxSum;
};

#### LeetCode（124） Binary Tree Maximum Path Sum

2015-12-27 16:20:25

#### Binary Tree Maximum Path Sum -- LeetCode

2014-04-05 02:19:00

#### [leetcode-124]Binary Tree Maximum Path Sum(c++)

2015-08-12 15:49:49

#### LeetCode 124: Binary Tree Maximum Path Sum 树形动态规划

2015-09-02 15:52:14

#### LeetCode Binary Tree Maximum Path Sum 解题报告

2014-02-06 22:43:45

#### [leetcode] 124. Binary Tree Maximum Path Sum

2015-07-03 13:58:25

#### LeetCode 124. Binary Tree Maximum Path Sum（二叉树最大路径和）

2016-05-27 00:27:32

#### 【LeetCode】Binary Tree Maximum Path Sum 解题报告

2015-01-22 16:15:05

#### [LintCode] Binary Tree Maximum Path Sum (二叉树中的最大路径和)

2015-08-02 21:29:31

#### leetcode_c++:树:Binary Tree Maximum Path Sum(124)

2016-08-26 15:37:22

## 不良信息举报

124. Binary Tree Maximum Path Sum（难）