/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* struct TreeNode *left;
* struct TreeNode *right;
* };
*/
int maxdeep;
void Maxdeep(struct TreeNode*root,int deep)
{
if(deep>maxdeep)
{
maxdeep=deep;
}
if(root->left!=NULL)Maxdeep(root->left,deep+1);
if(root->right!=NULL)Maxdeep(root->right,deep+1);
}
int maxDepth(struct TreeNode* root){
if(root==NULL)return 0;
maxdeep=-1;
Maxdeep(root,1);
return maxdeep;
}
二叉树的深度
最新推荐文章于 2024-02-22 12:51:35 发布