public static int maxPathSum2(TreeNode root) {
        if(root == null) return 0;
        if(root.left == null && root.right == null) return root.val;
        //helper[0] min, helper[1] leftMax, helper[2] rightMax
        int[] helper = new int[3];
        
        int max = 0;
        helper[0] = Integer.MIN_VALUE;
        helper[1] = Integer.MIN_VALUE;
        helper[2] = Integer.MIN_VALUE;
        int leftMax = maxPathSumHelper2(root.left, helper, true);
        int rightMax = maxPathSumHelper2(root.right,helper, false);
        max = Math.max((root.val+ leftMax+rightMax),Math.max(helper[1],helper[2]));
        if(max < helper[0]) max = helper[0];
    
        return max;
    }