0111. Minimum Depth
Easy | Tree + Level-order Traversal | 444 ms (99.47%), 49 MB (94.42%)
Last updated
Was this helpful?
Easy | Tree + Level-order Traversal | 444 ms (99.47%), 49 MB (94.42%)
Last updated
Was this helpful?
Source: GitHub:
Given a binary tree, find its minimum depth.
The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.
Note: A leaf is a node with no children.
While traversing the tree in level order, we need to record the current level (depth). Then, when we meet the leaf node, we return the current depth directly.