5
public int maxSumBST(TreeNode root) {10
// int[] = { min, max, sum };11
private int[] solve(TreeNode root) {12
if (root == null) return new int[] {Integer.MAX_VALUE, Integer.MIN_VALUE, 0};14
int[] left = solve(root.left);15
int[] right = solve(root.right);17
if (root.val > left[1] && root.val < right[0]) {18
int sum = left[2] + right[2] + root.val;19
ans = Math.max(ans, sum);20
return new int[] {Math.min(left[0], root.val), Math.max(root.val, right[1]), sum};23
return new int[] {Integer.MIN_VALUE, Integer.MAX_VALUE, 0};