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.
Input: root = [5,7,8]
Output: 2
Explanation:
The shortest path is 5 → 7 (or 5 → 8), so the minimum depth is 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.
Input: root = [10]
Output: 1
Explanation:
Only the root node exists, so the minimum depth is 1.
Accepted:
Submission: