/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* struct TreeNode *left;
* struct TreeNode *right;
* };
*/
struct TreeNode* lowestCommonAncestor(struct TreeNode* root, struct TreeNode* p, struct TreeNode* q) {
if(!root) return NULL;
if(root==p || root==q) return root;
struct TreeNode* left=lowestCommonAncestor(root->left,p,q);
struct TreeNode* right=lowestCommonAncestor(root->right,p,q);
if(left && right) return root;
if(left) return left;
if(right) return right;
if(!left && !right){
if(root==p || root==q) return root;
}
return NULL;
}
标签:right,TreeNode,struct,祖先,二叉树,return,236,root,left From: https://www.cnblogs.com/llllmz/p/18087771