124. Binary Tree Maximum Path Sum
class Solution { int maxPathSum; public int maxPathSum(TreeNode root) { maxPathSum=Integer.MIN_VALUE; seachPathSum(root); return maxPathSum; } private int seachPathSum(TreeNode node){ if(node==null) return 0; int left=Math.max(0, seachPathSum(node.left)); int right=Math.max(0, seachPathSum(node.right)); maxPathSum=Math.max(left+right+node.val, maxPathSum); return Math.max(left, right)+node.val; } }