//The problem is the minDepth(root->left)>=minDepth(root->right)

//if I use minDepth(root->left)>minDepth(root->right), the result is right, otherwise the result is wrong.

class Solution {

public:

//the problem

int minDepth(TreeNode* root) {

if(root == NULL)

return 0;

if(root->left == NULL)

return minDepth(root->right)+1;

if(root->right == NULL)

return minDepth(root->left)+1;

if(minDepth(root->left)>=minDepth(root->right)){

return minDepth(root->right) + 1;

}else{

return minDepth(root->left) + 1;

}

}

};