Advertisement
STANAANDREY

lsd8 ex8

Nov 18th, 2022 (edited)
843
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.64 KB | None | 0 0
  1. binary_tree = {"value": 2, "left":
  2.     {
  3.         "value": 7, "left": None, "right":
  4.         {
  5.             "value": 6, "left":
  6.             {
  7.                 "value": 5, "left": None, "right": None
  8.             }, "right":
  9.             {
  10.                 "value": 11, "left": None, "right": None
  11.             },
  12.         },
  13.     }, "right":
  14.                    {
  15.                        "value": 55, "left": None, "right": None
  16.                    }
  17.                }
  18.  
  19.  
  20. def get_height(tree):
  21.     if tree is None:
  22.         return -1
  23.  
  24.     return max(get_height(tree['left']), get_height(tree['right'])) + 1
  25.  
  26.  
  27. print(get_height(binary_tree))
  28.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement