*LeetCode-Binary Tree Maximum Path Sum
来源:互联网 发布:淘宝店技巧 编辑:程序博客网 时间:2024/06/10 01:38
写一个helper计算从这个点向下能到达的最大sum 然后每次更新全局最大sum 记得每次left 和 right 是要和0比较 因为可以不向下走 最下也是0
public class Solution { int max = Integer.MIN_VALUE; public int maxPathSum(TreeNode root) { maxDown ( root ); return max; } public int maxDown ( TreeNode node ){ if ( node == null ) return 0; int left = Math.max( 0, maxDown ( node.left ) ); int right = Math.max ( 0, maxDown ( node.right )); max = Math.max ( max, left + right + node.val ); return Math.max (left, right) + node.val; }}
0 0
- *****(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
- 【Leetcode】Binary Tree Maximum Path Sum
- LeetCode | Binary Tree Maximum Path Sum
- c++ primer学习笔记4_复合类型续
- Same Tree
- UVa 10129 - Play on Words
- svn与eclipse进行整合开发
- 前端框架【Bootstrap】框架体验评测
- *LeetCode-Binary Tree Maximum Path Sum
- Unity报错:Collection was modified; enumeration operation may not execute
- 【cpp】【函数】
- 黑马程序员——Java基础加强---反射
- 特权FPGA学习-笔记11-testbench学习(1)
- CSS图文列表中图片以正方形显示
- 2015书单 - 《异类》
- 10.9JAVA学习
- 黑马程序员——集合框架(四)