1
2
3
4
5
6
7
8
9

int maxDepth(TreeNode *root) 
{
    if (root == NULL) return 0;
    
    int leftDepth = maxDepth(root->left);
    int rightDepth = maxDepth(root->right);

    return (leftDepth > rightDepth ? leftDepth : rightDepth) + 1;
}
View Program Text


Test Status