4 ms C solution easy To understand


  • 4
    C
    int minDepth(struct TreeNode* root) {
     if( root == NULL ) return 0;
     int rDepth = minDepth( root->right ) + 1;
     int lDepth = minDepth( root->left ) + 1;
     if( root->right == NULL )
     {
         return lDepth;
     }
     else if( root->left == NULL )
     {
         return rDepth;
     }
     else
     {
         return rDepth < lDepth ? rDepth : lDepth;
     }
    
    }

  • 0
    E

    @ccccdx zan wonderful answer


Log in to reply
 

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