Tree BFS
LC #111Easy
Minimum Depth of Binary Tree
Tree BFS
AmazonGoogleMicrosoftProblem
Find the minimum depth — the shortest path from root to the nearest leaf node.
treebfsdfs
Constraints
- ›0 ≤ n ≤ 10⁵
- ›-1000 ≤ Node.val ≤ 1000
- ›A leaf is a node with no children
Example
Input
root = [3, 9, 20, null, null, 15, 7]Output
2Why
Shortest path root→leaf is 3→9 (depth 2). Not 3→20→15 (depth 3)