binary-tree-maximum-path-sum
来源:互联网 发布:淘宝怎么做详情页 编辑:程序博客网 时间:2024/06/05 06:55
题目:
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
Return6.
程序:
class Solution {public: int Max; int maxPathSum(TreeNode *root) { Max = INT_MIN; maxSum(root); return Max; } int maxSum(TreeNode *root){ if(root == NULL) return 0; int l_Max = max(0, maxSum(root->left)); int r_Max = max(0, maxSum(root->right)); Max = max(Max, l_Max + r_Max + root->val); return max(l_Max, r_Max) + root->val; }};
阅读全文
0 0
- Binary Tree Maximum Path Sum
- Binary Tree Maximum Path Sum
- Binary Tree Maximum Path Sum
- Binary Tree Maximum Path Sum
- Binary Tree Maximum Path Sum
- Binary Tree Maximum Path Sum
- Binary Tree Maximum Path Sum
- Binary Tree Maximum Path Sum
- Binary Tree Maximum Path Sum
- Binary Tree Maximum Path Sum
- Binary Tree Maximum Path Sum
- Binary Tree Maximum Path Sum
- Binary Tree Maximum Path Sum
- Binary Tree Maximum Path Sum
- Binary Tree Maximum Path Sum
- Binary Tree Maximum Path Sum
- Binary Tree Maximum Path Sum
- Binary Tree Maximum Path Sum
- 单态设计模式(Singleton Design Pattern)
- Codeblocks使用问题汇总
- instanceof
- Python __init__.py 模板
- 突破百度网盘下载限制(大文件直接下载、使用迅雷下载)
- binary-tree-maximum-path-sum
- 关于Ajax
- oracle索引操作等
- 【LibUIDK界面库系列文章】自绘List control的滚动条
- 看盘时这几个点需要特别留意
- Basic Tree--Data Structure
- JSON 之 SuperObject(14): 从 XML 中解析
- 数据结构 第8讲 KMP算法
- android Handler使用