C solution using recursion


  • 0
    int max (int a, int b) {
        return a > b ? a : b;
    }
    
    int maxDepth(struct TreeNode* root) {
        if (root) {
            return 1 + max(maxDepth(root->left), maxDepth(root->right));
        } else {
            return 0;
        }
    }
    

Log in to reply
 

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