欢迎光临
我们一直在努力

111. 二叉树的最小深度c

/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     struct TreeNode *left;
 *     struct TreeNode *right;
 * };
 */
int min(int i,int j){
    if(i>j) return j;
    return i;
}

int minDepth(struct TreeNode* root) {
    if(!root) return 0;
    int a=INT_MAX,b=INT_MAX;
    if(!root->left&&!root->right) return 1;
    if(root->left) a=minDepth(root->left)+1;
    if(root->right) b=minDepth(root->right)+1;
    return min(a,b);
}

未经允许不得转载:大有博文 » 111. 二叉树的最小深度c
分享到: 更多 (0)

大前端WP主题 更专业 更方便

联系我们联系我们