LeetCode - Binary Tree Maximum Path Sum 题解
来源:互联网 发布:淘宝网开店怎么开手机 编辑:程序博客网 时间:2024/06/06 02:17
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
.
思路:
后续遍历,遇到负的就截掉。
class Solution {public: int maxPathSum(TreeNode *root) { maxx = -2147483648; postOrder(root); return maxx; }private: int maxx; int postOrder(TreeNode *root){ if(!root) return 0; int l = postOrder(root->left); int r = postOrder(root->right); int v = max(l, r) + root->val; maxx = max(maxx, l + r + root->val); return max(v, 0); }};
0 0
- LeetCode - Binary Tree Maximum Path Sum 题解
- LeetCode 题解(97): 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
- [leetcode] Binary Tree Maximum Path Sum
- LeetCode - Binary Tree Maximum Path Sum
- LeetCode 124: Binary Tree Maximum Path Sum
- C++各大有名库的介绍
- 获取 本机 ip 地址
- Docker实践
- 经验分享:极速化 CocoaPods
- 字符串类String
- LeetCode - Binary Tree Maximum Path Sum 题解
- VC6 + ACE配置
- 12.3.2.1 使用高阶函数
- 常用汇编指令
- winsock
- MFC ActiveX开发笔记
- COM接口与抽象类
- TinyXml使用笔记
- jsoup解析网络HTML页,基本的使用方法