-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_bst.java
More file actions
28 lines (21 loc) · 735 Bytes
/
Copy pathcheck_bst.java
File metadata and controls
28 lines (21 loc) · 735 Bytes
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
/* 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 class is defined as follows:
class Node {
int data;
Node left;
Node right;
}
*/
boolean checkBST(Node root) {
return help(root,Integer.MAX_VALUE,Integer.MIN_VALUE);
}
boolean help(Node root,int h,int l) {
if(root == null)
return true;
else if(root.data >= h || root.data <=l)
return false;
else
{
return help(root.left,root.data,l) && help(root.right,h,root.data);
}
}