Accepted step by step 7 ms C solution


  • -1
    C
    if(root == NULL) {
        return 0;
    }
    if(root->left==NULL && root->right==NULL) {
        return 1;
    }
    else if(root->left && root->right==NULL) {
        return minDepth(root->left) + 1;
    }
    else if(root->right && root->left==NULL) {
        return minDepth(root->right) + 1;
    }
    int left = minDepth(root->left) + 1;
    int right = minDepth(root->right) + 1;
    return left < right ? left : right;

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.