2 Line code only


#1

`
int Solution::maxDepth(TreeNode* A) {
if(!A) return 0;
return max(maxDepth(A->left), maxDepth(A->right)) +1;
}

`The idea is to ask the left subtree, hey what is your max depth, and the right subtree. And return max of those two + 1 ( because of the node itself)


#2

You can do it in one line also by using ternary operator.