Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update Solution.java
  • Loading branch information
ThanhNIT committed Mar 21, 2022
commit 0043cf62605e6f53671680415aa700eda39cfd1f
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,28 @@

public class Solution {
public int maxSumBST(TreeNode root) {
isBst temp = checkBST(root);
isbst temp = checkBST(root);

return Math.max(temp.maxSum, 0);
}

private static class isBst {
private static class isbst {
int max = Integer.MIN_VALUE;
int min = Integer.MAX_VALUE;
boolean isBST = true;
int sum = 0;
int maxSum = Integer.MIN_VALUE;
}

private isBst checkBST(TreeNode root) {
private isbst checkBST(TreeNode root) {
if (root == null) {
return new isBst();
return new isbst();
}

isBst lp = checkBST(root.left);
isBst rp = checkBST(root.right);
isbst lp = checkBST(root.left);
isbst rp = checkBST(root.right);

isBst mp = new isBst();
isbst mp = new isbst();
mp.max = Math.max(root.val, Math.max(lp.max, rp.max));
mp.min = Math.min(root.val, Math.min(lp.min, rp.min));
mp.sum = lp.sum + rp.sum + root.val;
Expand Down