Recursive 5ms C Solution


  • 0
    C
    int maxDepth(struct TreeNode* root) {
        if(root == NULL) return 0;
        if(root->left == NULL && root->right == NULL && root != NULL) return 1;
        int leftMax = 0, rightMax = 0;
        if(root->left != NULL) leftMax = maxDepth(root->left) + 1;
        if(root->right!=NULL) rightMax = maxDepth(root->right) + 1;
        return (leftMax > rightMax) ? leftMax : rightMax;
        
    }
    

Log in to reply
 

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