Created
December 27, 2018 04:12
-
-
Save rushout09/8621bbc07b28c24d9aaa673fd832d71c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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