如果root=null return NULL
如果root等于任意一个寻找的节点返回root
如果LCA不在左子树上返回右子树结果
如果LCA不在右子树上返回左子树结果
如果既在左子树又在右子树上返回root
class Solution {
public:
TreeNode* lowestCommonAncestor(TreeNode* root, TreeNode* p, TreeNode* q) {
if(root == NULL) return NULL;
if(p == root || q == root) return root;
TreeNode* l = lowestCommonAncestor(root->left,p,q);
TreeNode* r = lowestCommonAncestor(root->right,p,q);
if(l == NULL) return r;
if(r == NULL) return l;
if(l && r) return root;
return NULL;
}
};