Tree: Height of a Binary Tree

  • + 0 comments

    PYTHON solution

    def height(root):
        left_h, right_h = 0, 0
        if root.left:
            left_h = 1 + height(root.left)
        if root.right:
            right_h = 1 + height(root.right)
        return max(left_h, right_h)