Tree: Height of a Binary Tree

  • + 0 comments

    C++, recursion.

        int height(Node* root) {
            if (!root || (!root->left && !root->right))
                return 0;
            return 1 + std::max(
                height(root->left),
                height(root->right)
            );
        }