Given the root node of a binary tree, can you determine if it's also a binary search tree?
You are not responsible for reading any input from stdin.
Hidden code stubs will assemble a binary tree and pass its root node to your function as an argument.Constraints: 0<=data<=10000
Моя функция проходит лишь 8 тестов из 14. Где здесь изъян?
def check_binary_search_tree_(root):
if root.left or root.right: lst=[root]
else: return 1
while lst:
new_list=[]
for node in lst:
if node.left:
if node.data>node.left.data: new_list.append(node.left)
else: return 0
if node.right:
if node.data<node.right.data: new_list.append(node.right)
else: return 0
lst=new_list
return 1