This is the best solution.4ms
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* struct TreeNode *left;
* struct TreeNode *right;
* };
*/
int max(int x, int y)
{
if(x<=y)
return y;
else
return x;
}
int maxDepth(struct TreeNode* root) {
if(root==NULL)
{
return 0;
}
else
{
return max(maxDepth(root->left),maxDepth(root->right))+1;
}
}