标签:des style blog ar color sp on div log
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)
标签:des style blog ar color sp on div log
原文地址:http://www.cnblogs.com/litao-tech/p/4168389.html