/**
* struct TreeNode {
* int val;
* struct TreeNode *left;
* struct TreeNode *right;
* };
*/
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param root TreeNode类
* @return int整型
*/
int MAX=0;
int depth=0;
int preorder(struct TreeNode* root){
depth++;
if(root==NULL){
depth--;
return 0;
}else{
if(MAX<depth){
MAX=depth;
}
preorder(root->left);
preorder(root->right);
}
depth--;
return 0;
}
int maxDepth(struct TreeNode* root ) {
// write code here
preorder(root);
return MAX;
}



京公网安备 11010502036488号