mirror of
https://github.moeyy.xyz/https://github.com/TheAlgorithms/C.git
synced 2023-10-11 15:56:24 +08:00
23 lines
401 B
C
23 lines
401 B
C
|
/**
|
||
|
* Definition for a binary tree node.
|
||
|
* struct TreeNode {
|
||
|
* int val;
|
||
|
* struct TreeNode *left;
|
||
|
* struct TreeNode *right;
|
||
|
* };
|
||
|
*/
|
||
|
|
||
|
int maxval(int a, int b) {
|
||
|
if (a > b)
|
||
|
return a;
|
||
|
else
|
||
|
return b;
|
||
|
}
|
||
|
int maxDepth(struct TreeNode* root){
|
||
|
if (root == NULL)
|
||
|
return 0;
|
||
|
else
|
||
|
return 1 + maxval(maxDepth(root->left), maxDepth(root->right));
|
||
|
}
|
||
|
|