1、题目
https://leetcode-cn.com/problems/minimum-depth-of-binary-tree/
2、题意
题解1:递归 没有子节点返回1,有子节点返回子节点的深度+1,取左右节点的最小值;
class Solution {
public:
int minDepth(TreeNode* root) {
if(!root) return 0;
int res = INT_MAX;
if(root->left) res = min(res,minDepth(root->left)+1);
if(root->right) res = min(res,minDepth(root->right)+1);
if(res==INT_MAX) return 1;
return res;
}
};