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

Because you program don't consider about this situation, if a tree only have left tree or right tree.
For example:
1  2
You program will get the wrong answer, since your function will return 0 from right and return 1 from left.
Then your min will give you 0. So you finally answer will be 1. but the real answer should be 2.