1class BTNode {
2 constructor(value) {
3 this.value = value;
4 this.left = null;
5 this.right = null;
6 }
7}
8
9/**
10 *
11 * @param {BTNode} tree
12 * @returns {Boolean}
13 */
14const isBinarySearchTree = (tree) => {
15 if (tree) {
16 if (
17 tree.left &&
18 (tree.left.value > tree.value || !isBinarySearchTree(tree.left))
19 ) {
20 return false;
21 }
22 if (
23 tree.right &&
24 (tree.right.value <= tree.value || !isBinarySearchTree(tree.right))
25 ) {
26 return false;
27 }
28 }
29 return true;
30};
11 def checkBST(t)
22 return false if t==nil
33 if t.left!=nil && t.left>t
44 return false
55 end
66 if t.right!=nil && t.right<t
77 return false
88 end
99 if checkBST(t.left) && checkBST(t.right)
1010 return true
1111 end
1212 end
13