1- from typing import Optional , List
2-
3-
41class Node :
52 def __init__ (self , info : int ) -> None :
63 self .info : int = info
7- self .left : Optional [ " Node" ] = None
8- self .right : Optional [ " Node" ] = None
4+ self .left : Node | None = None
5+ self .right : Node | None = None
96
107 def __str__ (self ) -> str :
118 """
@@ -14,10 +11,9 @@ def __str__(self) -> str:
1411 """
1512 return str (self .info )
1613
17-
1814class BinarySearchTree :
1915 def __init__ (self ) -> None :
20- self .root : Optional [ Node ] = None
16+ self .root : Node | None = None
2117
2218 def create (self , val : int ) -> None :
2319 """
@@ -49,8 +45,7 @@ def create(self, val: int) -> None:
4945 else :
5046 break
5147
52-
53- def height (node : Optional [Node ]) -> int :
48+ def height (node : Node | None ) -> int :
5449 """
5550 >>> height(None)
5651 -1
@@ -67,8 +62,7 @@ def height(node: Optional[Node]) -> int:
6762 return - 1
6863 return 1 + max (height (node .left ), height (node .right ))
6964
70-
71- def tree_height_from_list (data : List [int ]) -> int :
65+ def tree_height_from_list (data : list [int ]) -> int :
7266 """
7367 >>> tree_height_from_list([3,2,5,6])
7468 2
@@ -82,8 +76,6 @@ def tree_height_from_list(data: List[int]) -> int:
8276 bst .create (x )
8377 return height (bst .root )
8478
85-
8679if __name__ == "__main__" :
8780 import doctest
88-
8981 doctest .testmod ()
0 commit comments