public class Solution {

static int min=1000000;

static int max=0;

public int minDepth(TreeNode root)

{

```
if(root==null) {return 0;}
int answer =Cal(root,1);
return min;
}
public int Cal(TreeNode Node,int Depth)
{
boolean flag=false;
if(Node.left!=null)
{
flag=true;
Depth= Cal(Node.left,++Depth);
}
if(Node.right!=null)
{
flag=true;
Depth= Cal(Node.right,++Depth);
Depth-=1;
}
else
{
if(Depth>=max){ max=Depth; }
if(Depth<=min&&flag==false){ min=Depth; }
Depth-=1;
}
return Depth;
}
```

}