-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidatebst.cpp
More file actions
63 lines (51 loc) · 1.29 KB
/
validatebst.cpp
File metadata and controls
63 lines (51 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <bits/stdc++.h>
using namespace std;
using ll=long long int;
struct TreeNode {
int val;
TreeNode *left;
TreeNode *right;
TreeNode() : val(0), left(nullptr), right(nullptr) {}
TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
};
class Solution
{
public:
TreeNode* prev = nullptr;
int isBST(TreeNode* node)
{
if(node == nullptr){
return true;
}
cout<<"working"<<endl;
if(prev != nullptr){
cout<<"dfkfmnklsd";
}
bool res = isBST(node->left);
if(prev != nullptr && prev->val >= node->val){
cout<<"fmknfklsdn";
return false;
}
prev = node;
bool res1 = isBST(node->right);
return res && res1;
}
bool isValidBST(TreeNode* root) {
return isBST(root);
}
};
void solve(){
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t=1;
cin>>t;
while(t--){
solve();
}
return 0;
}