Binary Tree Maximum Path Sum
来源:互联网 发布:工行大数据应用案例 编辑:程序博客网 时间:2024/04/29 08:12
/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */class Solution { void DFS(TreeNode *root,int &tsum,int &maxsum){ if(root==NULL){ tsum=0; return; } int lsum=0,rsum=0; DFS(root->left,lsum,maxsum); DFS(root->right,rsum,maxsum); tsum=max(root->val,max(lsum+root->val,rsum+root->val)); maxsum=max(maxsum,max(tsum,lsum+rsum+root->val)); }public: int maxPathSum(TreeNode *root) { // Start typing your C/C++ solution below // DO NOT write int main() function int maxsum=INT_MIN,tsum; DFS(root,tsum,maxsum); return maxsum; }};
- 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
- struts2中token的令牌机制
- ruby类2
- Objective-C的认识
- [二叉树] 先序非归递遍历算法
- 数字图像处理领域的二十四个典型算法及vc实现、第二章
- Binary Tree Maximum Path Sum
- SQL Alias(别名)
- 多线程間通信
- Google安全团队对Android安全的认识
- 公司运作 - 利润率、周转率
- iOS中Cell高度如何能够自动适应需要显示的内容
- ActiveReports 报表应用教程 (10)
- SQL JOIN
- Android图片异步加载之Android-Universal-Image-Loader