class Node: def __init__(self,mark,left,right): self.mark = mark self.left = left self.right = right def height(tree:Node) -> int: if (tree is None): return -1 else: return (max(height(tree.left),height(tree.right))+1) tree = Node ('*', Node ('+', Node (6 , None , None ) , Node (5 , None , None )) , Node (1 , None , None ))
max
Quote:Why we must return -1 if the tree is none ?
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)