Write a function that checks if a given binary search tree contains a given value. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Write a function that checks if a given binary search tree contains a given value.

Im taking this little test on a website and its telling me that i passed the first test case but not the other two this is what i got class BinarySearchTree: Node = collections.namedtuple('Node', ['left', 'right', 'value']) @staticmethod def contains(root, value): if root.value == None: return False if root.value == value: return True elif root.value > value: return root.left.value == value return root.right.value == value n0 = BinarySearchTree.Node(value=0, left = None, right=None) n1 = BinarySearchTree.Node(value=1, left=n0, right=None) n3 = BinarySearchTree.Node(value=3, left=None, right=None) n2 = BinarySearchTree.Node(value=2, left=n1, right=n3) print(BinarySearchTree.contains(n2, 3)) OUTPUT: True

15th Apr 2018, 3:20 AM
fds fds
fds fds - avatar
1 Answer
0
what are your other test cases? you only gave the true one.
23rd Apr 2018, 3:14 PM
Michael Gribskov
Michael Gribskov - avatar