int finddepth(struct TreeNode* root,int n,int* father)
{
if(root==NULL) return 0;
if(root->val==n) return 1;
if(root->left!=NULL&&root->left->val==n||root->right!=NULL&&root->right->val==n) (*father)=root->val;
int left=finddepth(root->left,n,father);
int right=finddepth(root->right,n,father);
if(left!=0) return left+1;
if(right!=0) return right+1;
return 0;
}
/*void findfather(struct TreeNode* root,int n,int* father)
{
if(root==NULL) return ;
if(root->left!=NULL&&root->left->val==n||root->right!=NULL&&root->right->val=
993.二叉树的堂兄弟节点
最新推荐文章于 2023-04-22 21:03:38 发布
![](https://img-home.csdnimg.cn/images/20240611030827.png)