You are viewing a single comment's thread. Return to all comments →
My code is:
def isBST(root): if root.left and root.left.data >= root.data: return False if root.left: print(root.left.data,"<",root.data) if root.right and root.right.data <= root.data: return False if root.right: print(root.right.data,">",root.data) return True def checkBST(root): if not isBST(root): return False if root.left: checkBST(root.left) if root.right: checkBST(root.right) return True
Input:
2 1 2 4 3 5 6 7
Output:
2 < 3 6 > 3 1 < 2 4 > 2 5 < 6 7 > 6 Yes
Can anyone please where is the problem?
Seems like cookies are disabled on this browser, please enable them to open this website
Trees: Is This a Binary Search Tree?
You are viewing a single comment's thread. Return to all comments →
My code is:
Input:
Output:
Can anyone please where is the problem?