Tree: Height of a Binary Tree

  • + 0 comments
    Python:
    
    `def height(root):
    	if root.left == None and root.right== None:
    		return 0
    	elif root.left == None:
    		return 1+ height(root.right)
    	elif root.right == None:
    		return 1+ height(root.left)
    	else:
    		return 1 + max(height(root.left),height(root.right))`