I\'m trying to solve this problem but I\'m having some troubles:
In a binary search tree (BST):
- The data value of every node in a
A BST is defined as:
-The left subtree of a node always contains nodes with values less than that of the node. - The right subtree of a node always contains nodes with values greater than that of the node. -Both left and right sub trees are also valid BSTs.
class Solution {
public boolean isValidBST(TreeNode root) {
return helper (root,Integer.MIN_VALUE,Integer.MAX_VALUE);
}
public boolean helper(TreeNode root,long low,long high){
if (root==null){
return true;
}
if (root.valhigh){
return false;
}
return (helper(root.left,low,root.val-1) &&
helper(root.right,root.val+1,high));
}
}