File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11from typing import Optional , List
22
3+
34class Node :
45 def __init__ (self , info : int ) -> None :
56 self .info : int = info
@@ -13,6 +14,7 @@ def __str__(self) -> str:
1314 """
1415 return str (self .info )
1516
17+
1618class BinarySearchTree :
1719 def __init__ (self ) -> None :
1820 self .root : Optional [Node ] = None
@@ -47,6 +49,7 @@ def create(self, val: int) -> None:
4749 else :
4850 break
4951
52+
5053def height (node : Optional [Node ]) -> int :
5154 """
5255 >>> height(None)
@@ -64,6 +67,7 @@ def height(node: Optional[Node]) -> int:
6467 return - 1
6568 return 1 + max (height (node .left ), height (node .right ))
6669
70+
6771def tree_height_from_list (data : List [int ]) -> int :
6872 """
6973 >>> tree_height_from_list([3,2,5,6])
@@ -78,6 +82,8 @@ def tree_height_from_list(data: List[int]) -> int:
7882 bst .create (x )
7983 return height (bst .root )
8084
85+
8186if __name__ == "__main__" :
8287 import doctest
88+
8389 doctest .testmod ()
You can’t perform that action at this time.
0 commit comments