Detailed c++ code


  • 0
    A
     int maxDepth(TreeNode* root) {
            
            if(root==NULL)
                return 0;
            
             
            int l=  maxDepth(root->left)+1;
     //for every recursive call l and r are calculated
            int r= maxDepth(root->right)+1;
           
    //maximum subtree is calculated
                if(l>r)
                {
                    return l;
                }
                else    
                {   return r;
                }
            
            
        }
    

Log in to reply
 

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