Easy · Trees

Maximum Depth of Binary Tree

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

Core interview problems are free with a full runner and lessons; Pro opens the complete library.

More Trees problems