Skip to content

Commit 4746e3e

Browse files
authored
Update binary_search_tree.py
1 parent fb4cb73 commit 4746e3e

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

search/binary_search_tree.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,16 @@ def insert(self, value):
2626
def contains(self, target):
2727
if self.value == target:
2828
return True
29-
if self.left:
30-
if self.left.contains(target):
31-
return True
32-
if self.right:
33-
if self.right.contains(target):
34-
return True
35-
return False
29+
if target < self.value:
30+
if not self.left:
31+
return False
32+
else:
33+
return self.left.contains(target)
34+
else:
35+
if not self.right:
36+
return False
37+
else:
38+
return self.right.contains(target)
3639

3740
def get_max(self):
3841
if not self:

0 commit comments

Comments
 (0)