public int maxPathSum(TreeNode root) {
max[0] = Integer.MIN_VALUE;
findMaxPathSum(root, max);
public int findMaxPathSum(TreeNode node, int[] max) {
int leftPathSum = Math.max(0, findMaxPathSum(node.left, max));
int rightPathSum = Math.max(0, findMaxPathSum(node.right, max));
max[0] = Math.max(max[0], node.val + leftPathSum + rightPathSum);
return node.val + Math.max(leftPathSum, rightPathSum);