一、
1 class Solution { 2 public: 3 TreeNode *lowestCommonAncestor(TreeNode *root, TreeNode *A, TreeNode *B) { 4 if (root == NULL || root == A || root == B) { 5 return root; 6 } 7 TreeNode* left = lowestCommonAncestor(root->left, A, B); 8 TreeNode* right = lowestCommonAncestor(root->right, A, B); 9 if (left != NULL && right != NULL) { 10 return root; 11 } 12 if (left != NULL) { 13 return left; 14 } 15 if (right != NULL) { 16 return right; 17 } 18 return NULL; 19 } 20 };