```
public int minDepth(TreeNode root) {
int res = 0 ;
if(root == null) return res;
LinkedList<TreeNode> queue = new LinkedList<>();//Always like linkedList
queue.offer(root);//offer the root
while(queue.size() > 0)//let do the level traverse
{
res++;// res add one when we are at a new level
int size = queue.size();//Remember the level size so you do not mess up
for(int i = 0 ; i < size ; i++)
{
TreeNode node = queue.poll();
//If there is a node who do not have any child, then it is a leaf and we can stop here.
if(node.left == null&&node.right == null)
return res;
//offer the child or children to the queue for the analysis of the next level
if(node.left != null)
queue.offer(node.left);
if(node.right != null)
queue.offer(node.right);
}
}
return res;
}
```

1 ms, not bad. If you like it, please thumb me up or leave you comments bellow to communicate.