LeetCode之Binary Tree Maximum Path Sum
来源:互联网 发布:上海软件编程培训机构 编辑:程序博客网 时间:2024/06/17 17:12
/* 参考自:http://www.cnblogs.com/TenosDoIt/p/3435366.html*/class Solution {public: int maxPathSum(TreeNode* root) { if(root == nullptr) return 0; int maxPath = INT_MIN; maxPathSum(root, maxPath); return maxPath; } int maxPathSum(TreeNode *root, int &maxPath){ //if(root == nullptr) return 0; int left(0), right(0); if(root->left) left = maxPathSum(root->left, maxPath); if(root->right) right = maxPathSum(root->right, maxPath); int tmp = max(root->val, max(root->val+left, root->val+right)); maxPath = max(maxPath, max(tmp, root->val + left + right)); return tmp; }};
0 0
- leetcode之Binary Tree Maximum Path Sum
- Leetcode之Binary Tree Maximum Path Sum
- LeetCode之Binary Tree Maximum Path Sum
- LeetCode之Binary Tree Maximum Path Sum
- leetcode之Binary Tree Maximum Path Sum
- *****(leetcode) Binary Tree Maximum Path Sum (tree)
- LeetCode Binary Tree Maximum Path Sum
- [Leetcode] Binary Tree Maximum Path Sum
- [leetcode] Binary Tree Maximum Path Sum
- LeetCode Binary Tree Maximum Path Sum
- [LeetCode] Binary Tree Maximum Path Sum
- leetcode Binary Tree Maximum Path Sum
- 【leetcode】Binary Tree Maximum Path Sum
- LeetCode - Binary Tree Maximum Path Sum
- [LeetCode]Binary Tree Maximum Path Sum
- [Leetcode]Binary Tree Maximum Path Sum
- Leetcode: Binary Tree Maximum Path Sum
- LeetCode-Binary Tree Maximum Path Sum
- 如何在QML应用中创建一个Context Menu
- 黑马程序员—面向对象
- hibernate持久化对象的三个状态
- sql跨数据库批量插入
- Android自定义View的注意点
- LeetCode之Binary Tree Maximum Path Sum
- [leetcode] 240 Search a 2D Matrix II
- 使用Python将csv文件批量化导入SQL Server
- 下载安装并修改wamp配置文件
- 结果体和联合体
- centos下 安装 rvm
- 139. Word Break
- [C++]Ugly Number 丑数
- STL heap部分源码分析