struct TreeNode* low(struct TreeNode* root, int o1, int o2) {
if (root == NULL || root->val == o1 || root->val == o2) {
return root;
}
struct TreeNode* left = low(root->left, o1, o2);
struct TreeNode* right = low(root->right, o1, o2);
if (left != NULL && right != NULL) {
return root;
}
return left != NULL ? left : right;
}
int lowestCommonAncestor(struct TreeNode* root, int o1, int o2 ) {
return low(root,o1,o2)->val;
}

京公网安备 11010502036488号