Given the root node of a binary tree, write a program to find its minimum depth.

Problem Note

  • The minimum depth is the number of nodes along the shortest path from the nearest leaf node to the root.
  • A leaf is a node with no children.

Example 1

Input: Given a binary tree [10,5,15,null,null,11,6]
    10
   / \
  5  15
    /  \
   11   6
Output: 2
Explanation: Shortest path to leaf is 10 -> 5

Example 2

Input: Given a binary tree [1,null,2]
         1
          \
           2
Output: 2
Explanation: Shortest path to leaf is 1 -> 2