一、题目内容
二、题解
解法1:
思路
代码
public class Solution {int ans = Integer.MIN_VALUE;public int maxPathSum (TreeNode root) {if(root == null){return 0;}recur(root);return ans;}public int recur(TreeNode root){if (root == null) {return 0;}int leftMax = Math.max(recur(root.left),0);int rightMax = Math.max(recur(root.right),0);ans = Math.max(ans,root.val+leftMax+rightMax);return root.val+Math.max(leftMax,rightMax);}}
