/**
* 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 NULL;
}
//默认先算上第一层
int leftcount = 1;
int rightcount = 1;
leftcount += maxDepth(root->left);
rightcount += maxDepth(root->right);
//哪个深度大返回哪个
if (leftcount >= rightcount) {
return leftcount;
} else {
return rightcount;
}
}
https://leetcode-cn.com/problems/er-cha-shu-de-shen-du-lcof/