解题思路:DFS遍历整棵树,取最小深度
class Solution {
public:
int minDepth(TreeNode* root) {
if(root == NULL)
return 0;
if(root->left == NULL)
return 1+minDepth(root->right);
if(root->right == NULL)
return 1+minDepth(root->left);
return min(1+minDepth(root->left),1+minDepth(root->right));
}
};