二叉树的最小深度

来源:互联网 发布:java区块链开源项目 编辑:程序博客网 时间:2024/04/30 12:52
class Solution {public:    int minDepth(TreeNode* root) {        if(root == NULL) return 0;        int leftDep = minDepth(root->left);        int rightDep = minDepth(root->right);        if(leftDep == 0 && rightDep == 0) return 1;//叶子节点        if(leftDep == 0) leftDep = INT_MAX;        if(rightDep == 0) rightDep = INT_MAX;//中间节点        return min(leftDep, rightDep) + 1;     }};
0 0