Tree: Height of a Binary Tree

  • + 0 comments

    Java 8, O(log n)

    public static int height(Node root) {
                if (root == null) {
                    return -1;
                } else {
                    return 1 + Math.max(height(root.left), height(root.right));
                }
            }