leetcode 104. Maximum Depth of Binary Tree

Orignal question can be found here.

My solution is as follows:

int maxDepth(struct TreeNode* root)
{
        if(root == NULL)
                return 0;
        int left_child_depth = maxDepth(root->left);
        int right_child_depth = maxDepth(root->right);
        return left_child_depth>=right_child_depth ? (left_child_depth+1):(right_child_depth+1);
}

Leave a Reply