4 ms Solution in C


  • 1
    S

    int minDepth(struct TreeNode* root) {

    if(root==NULL)
      return 0;
    if(root->left==NULL && root->right==NULL)
      return 1;
      
    int rD=0,lD=0;
    
    
    rD=minDepth(root->left);
    lD=minDepth(root->right);
    
    if(rD==0)
        return 1+lD;
    else if(lD==0)
        return 1+rD;
    else
        return rD>lD?1+lD:1+rD;
    

    }


Log in to reply
 

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