class Solution {
public:
int minDepth(TreeNode* root) {
if(root == 0) return 0;
int depth ;
if(root!=0)
{
depth = 1;
int L = minDepth(root->left);
int R = minDepth(root->right);
if(L && R)
{
int min = R>L?L:R;
depth += min;
}
else if(L == 0) depth+= R;
else if(R== 0) depth += L;
}
return depth;
}
};