Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Minimum Depth of Binary Tree: Problem

XPChallenge Points: 10
levelLevel: Easy

Given the root of a binary tree, return the minimum depth—the number of nodes along the shortest path from the root to the nearest leaf node.
A leaf node is a node with no children.

Example 1:

Input: root = [5,7,8]

Output: 2

Explanation:

The shortest path is 5 → 7 (or 5 → 8), so the minimum depth is 2.

Example 2:

Input: root = [1,null,2,null,3,null,4]

Output: 4

Explanation:

There’s only one path: 1 → 2 → 3 → 4, so the minimum depth is 4.

Example 3:

Input: root = [10]

Output: 1

Explanation:

Only the root node exists, so the minimum depth is 1.

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result