You are viewing a single comment's thread. Return to all comments →
I like the approach with inorder traverse. But we have to check not only the order, but also that there are no duplicates. I used "set" for that:
list(set(my_list))
Here is my code:
def checkBST(root): list_ = [] def inorder(node): if node.data: if node.left: inorder(node.left) list_.append(node.data) if node.right: inorder(node.right) return list_ inorder_list = inorder(root) return sorted(list(set(inorder_list))) == inorder_list
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 →
I like the approach with inorder traverse. But we have to check not only the order, but also that there are no duplicates. I used "set" for that:
Here is my code: