2 alternate solutions C++


#1
int Solution::maxDepth(TreeNode* A) {
    //   if(!A) // Super easy solution
    //     return 0;
        
    // return 1 + max(maxDepth(A -> left), maxDepth(A -> right));
    
    //Slightly bigger one
    if(A != nullptr){
        if(A->left == nullptr && A->right == nullptr) return 1; //leaf
        int l = maxDepth(A->left);
        int r = maxDepth(A->right);
        return 1+max(l,r);
    } else return 0; //after leaf
    
}