Given the root of a binary tree, return 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. Pattern focus: Recursive Tree Metrics. Be careful with nodes that have only one child.
root = binary tree root
minimum depth of the tree
Example 1:
Input:
root = [3,9,20,null,null,15,7]
Output:
2
Explanation:
The nearest leaf is the node 9 at depth 2.
Example 2:
Input:
root = [2,null,3,null,4,null,5]
Output:
4
Explanation:
There is only one path from root to leaf.