# 111. Minimum Depth of Binary Tree

### Description

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.

### Constraints

### Approach

### Links

* [GeeksforGeeks](https://www.geeksforgeeks.org/find-minimum-depth-of-a-binary-tree/)
* [Leetcode](https://leetcode.com/problems/minimum-depth-of-binary-tree/)
* [ProgramCreek](https://www.programcreek.com/2013/02/leetcode-minimum-depth-of-binary-tree-java/)
* YouTube

### **Examples**

{% tabs %}
{% tab title="Example 1" %}
**Input:** \[3, 9, 20, null, null, 15, 7]

<div align="left"><img src="https://1091135627-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MEmU-aGQcUvtjjAH8_3%2F-MFzKfQ1tMHMHQS60LNK%2F-MFzN4L8KcsHLcTjRYbo%2Fimage.png?alt=media&#x26;token=6c431ffe-3b75-4166-8494-93a040d882f1" alt=""></div>

**Output:** 2
{% endtab %}
{% endtabs %}

### **Solutions**

{% tabs %}
{% tab title="TreeNode" %}

```java
// Definition for a binary tree node.
public class TreeNode {
    int val;
    TreeNode left;
    TreeNode right;
    
    TreeNode() {}
    
    TreeNode(int val) { this.val = val; }
    
    TreeNode(int val, TreeNode left, TreeNode right) {
        this.val = val;
        this.left = left;
        this.right = right;
    }
}
```

{% endtab %}

{% tab title="Solution 1" %}

```java
/**
 * Time complexity : 
 * Space complexity : 
 */

class Solution {
    public int minDepth(TreeNode root) {
        if(root == null) return 0;
        
        if(root.left == null) {
            return 1 + minDepth(root.right);
        }
        
        if(root.right == null) {
            return 1 + minDepth(root.left);
        }
        
        return 1 + Math.min(minDepth(root.left), minDepth(root.right));
    }
}
```

{% endtab %}
{% endtabs %}

### **Follow up**

*
