← All problems

Maximum Depth of Binary Tree

easy

Given the root of a binary tree, return its maximum depth — the number of nodes along the longest path from root to a leaf.

Trees are shown below as level-order arrays with null for missing children (e.g. [3, 9, 20, null, null, 15, 7]); AlgoLens builds the real { val, left, right } node structure before your function runs.

Example

Input: root = [3, 9, 20, null, null, 15, 7]
Output: 3
Loading...