Tree: Height of a Binary Tree

  • + 2 comments

    NO. they haven't mentioned that in the problem. but in editorial they return -1 for root == Null because:

    def height(root):
        if root:
            return 1 + max(height(root.left), height(root.right))
        else:
            return -1
    

    because they return 1 + max(root.left+root.right) now if root.left or root.right were null then max(blah blah) will return -1 and together they would return 0 as height of that root without left or right subtree..