Easy · Trees

Get height

Given the root of a binary tree, return its height: the number of nodes on the longest path from the root down to a leaf (0 for an empty tree).

Examples

Example 1

[3,9,20,·,·,15,7]

Output: height 3

Example 2

[1,2,3,4,·,·,·,8]

Output: height 4

Rebuild it in the studio

Read every interview problem free. Ten rooms need no account. A token opens a problem in full — Pro never counts.

More Trees problems