struct node{
int data;
node* lchild;
node* rchild;
};
node* Lca(node* root,node* p,node* q){
if(root==NULL)
return NULL;
if(root==p||root==q)
return root;
node* left=Lca(root->lchild,p,q);
node* right=Lca(root->rchild,p,q);
if((left==p&&right==q)||(left==q)&&(right==p))
return root;
else
return (left!=NULL)?left:right;
}
转载于:https://my.oschina.net/zshuangyan/blog/173256