I am using an array with only one element as a function parameter.

```
public class Solution {
public int maxPathSum(TreeNode root) {
if (root==null) return 0;
int[] max={Integer.MIN_VALUE};
maxTree(root,max);
return max[0];
}
//@Param:return the sum of the root value and largest branch
private int maxTree(TreeNode root,int[] max){
if (root==null) return 0;
int left=root.left!=null?maxTree(root.left,max):Integer.MIN_VALUE;
int right=root.right!=null?maxTree(root.right,max):Integer.MIN_VALUE;
max[0]=Math.max(max[0],(left>0?left:0)+(right>0?right:0)+root.val);
return root.val+((left>0||right>0)?Math.max(left,right):0);
}
}
```