> For the complete documentation index, see [llms.txt](https://ucan.gitbook.io/notes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ucan.gitbook.io/notes/tree/111.-minimum-depth-of-binary-tree.md).

# 111. Minimum Depth of Binary Tree

{% hint style="info" %}
leaf: node that does not have a children\
depth: from root to leaf
{% endhint %}

```java

class Solution {
    int result = Integer.MAX_VALUE;
    public int minDepth(TreeNode root) {
        if (root==null) return 0;
        dfs(root, 1);
        return result;
    }
    
    private void dfs(TreeNode node, int depth){
        if(node.left!=null){
            dfs(node.left, depth+1);
        }
        if(node.right!=null){
            dfs(node.right, depth+1);
        }
        if (node.right == null && node.left ==null){
            result=Math.min(result, depth);
            return;
        }
    }
}
```
