const int MIN_VALUE = -50000;
const int MAX_VALUE = 50000;
bool isValidBST( node *root) {
return isvalidHelper(root, MIN_VALUE, MAX_VALUE);
}
bool isvalidHelper(node *root, int min, int max) {
if(root == null) return true;
if ( root->value < min || !isvalidHelper(root->left, min, root->value)
return false;
if ( root->value > max || !isvalidHelper(root->right, root->value, max)
return false;
return true;
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment