/**
* struct TreeNode {
* int val;
* struct TreeNode *left;
* struct TreeNode *right;
* };
*/
class Solution {
public:
/**
*
* @param root TreeNode类
* @param o1 int整型
* @param o2 int整型
* @return int整型
*/
int ans;
bool helper(TreeNode* root, int o1, int o2){
if(root == NULL) return false;
bool isLeft = helper(root -> left, o1, o2);
bool isRight = helper(root -> right, o1, o2);
if((isLeft && isRight)
|| (isLeft && (root -> val == o1 || root -> val == o2))
|| (isRight && (root -> val == o1 || root -> val == o2))) ans = root -> val;
return isLeft || isRight || root -> val == o1 || root -> val == o2;
}
int lowestCommonAncestor(TreeNode* root, int o1, int o2) {
// write code here
helper(root, o1, o2);
return ans;
}
};