Skip to content

Commit 032cd0e

Browse files
authored
Create main.cpp
1 parent 5491e83 commit 032cd0e

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class Solution {
2+
public:
3+
bool isBST(Node* root, Node* & prev){
4+
if(root == NULL) return true;
5+
6+
if(!isBST(root -> left, prev)) return false;
7+
8+
if(prev != NULL && root -> data <= prev -> data) return false;
9+
10+
prev = root;
11+
12+
return isBST(root -> right, prev);
13+
14+
}
15+
16+
bool isBST(Node* root) {
17+
Node* prev = NULL;
18+
return isBST(root, prev);
19+
}
20+
};

0 commit comments

Comments
 (0)