1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* struct TreeNode *left;
* struct TreeNode *right;
* };
*/
int maxDepth(struct TreeNode* root) {
if(root == NULL)
return 0;
int x = maxDepth(root->left);
int y = maxDepth(root->right);
if(x>y)
return x+1;
else return y+1;
}