```
public int minDepth(TreeNode root) {
if(root==null)
return 0;
int a = minDepth(root.left);
int b = minDepth(root.right);
if((a+b)==0)
return 1;
if(a*b==0)
return a+b+1;
if(a<b)
{return a+1;}
else {return b+1;}
}
```