Skip to content

Instantly share code, notes, and snippets.

@rushout09
Created December 27, 2018 04:12
Show Gist options
  • Save rushout09/8621bbc07b28c24d9aaa673fd832d71c to your computer and use it in GitHub Desktop.
Save rushout09/8621bbc07b28c24d9aaa673fd832d71c to your computer and use it in GitHub Desktop.
/* Hidden stub code will pass a root argument to the function below. Complete the function to solve the challenge. Hint: you may want to write one or more helper functions.
The Node struct is defined as follows:
struct Node {
int data;
Node* left;
Node* right;
}
*/
#include <climits>
bool isBST(Node *root, int min, int max){
if(root==NULL)
return true;
else
{
if(root->data < min || root->data > max)
return false;
else{
return isBST(root->left, min, root->data - 1) && isBST(root->right, root->data + 1, max);
}
}
}
bool checkBST(Node* root) {
return isBST(root, INT_MIN, INT_MAX);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment