Given a binary search tree(BST), find the lowest common ancestor of two given nodes in the BST.
Node* LCA(Node* root, Node* p, Node* q) { if (!root || !p || !q) return NULL; if (max(p->data, q->data) < root->data) return LCA(root->left, p, q); else return LCA(root->right, p, q); else return root; }
Lowest Common Ancestor of a Binary Search Tree (BST)
原文:http://www.cnblogs.com/litao-tech/p/4168389.html