LeetCode #124 Binary Tree Maximum Path Sum
来源:互联网 发布:mac u盘查杀软件 编辑:程序博客网 时间:2024/05/17 02:24
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
.
/** * 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; int res = root->val; getMax(root, res); return res; } int getMax(TreeNode *root, int &res){ if(root == NULL) return 0; int left = getMax(root->left,res); int right = getMax(root->right, res); res = max(res, left + right + root->val); return max(0, max(left, right) + root->val); }};
0 0
- LeetCode 124: Binary Tree Maximum Path Sum
- LeetCode 124 Binary Tree Maximum Path Sum
- LeetCode: Binary Tree Maximum Path Sum [124]
- LeetCode 124 Binary Tree Maximum Path Sum
- LeetCode(124) Binary Tree Maximum Path Sum
- [LeetCode 124]Binary Tree Maximum Path Sum
- leetcode || 124、Binary Tree Maximum Path Sum
- LeetCode #124 Binary Tree Maximum Path Sum
- leetcode 124: Binary Tree Maximum Path Sum
- 124 Binary Tree Maximum Path Sum [Leetcode]
- LeetCode 124: Binary Tree Maximum Path Sum
- LeetCode 124:Binary Tree Maximum Path Sum
- LeetCode 124 Binary Tree Maximum Path Sum
- Leetcode 124 Binary Tree Maximum Path Sum
- Leetcode #124 Binary Tree Maximum Path Sum
- Leetcode-124: Binary Tree Maximum Path Sum
- *****(leetcode) Binary Tree Maximum Path Sum (tree)
- LeetCode Binary Tree Maximum Path Sum
- 五种主要多核并行编程方法分析与比较
- 解决MySQL查询不区分大小写
- Android主线程到底是什么(二)
- Js://计算天数
- OAuth那些事儿
- LeetCode #124 Binary Tree Maximum Path Sum
- PreferenceActivity 学习
- JavaSE File类详细介绍
- 黑马程序员——JavaBean
- 保持业务数据同步
- 不相交集ADT
- 名字的漂亮度
- 后台调用js,给同一个事件绑定一个方法
- centos 6.5-hadoop-2.2.0配置hive1.2.1