题目链接
https://leetcode-cn.com/problems/minimum-depth-of-binary-tree/
个人题解
class Solution {
private:
int min_h;
void dfs(TreeNode * root, int h){
if (root==nullptr)return;
dfs(root->left,h+1);
if(root->left==nullptr && root->right==nullptr){
min_h = min(min_h,h);
}
dfs(root->right,h+1);
}
public:
int minDepth(TreeNode* root) {
if(root==nullptr)return 0;
min_h=1000000;
dfs(root,1);
return min_h;
}
};