要求
示例
思路
实现
1 class Solution { 2 public: 3 TreeNode* lowestCommonAncestor(TreeNode* root, TreeNode* p, TreeNode* q) { 4 5 assert( p != NULL && q != NULL ); 6 7 if( root == NULL ) 8 return NULL; 9 10 if( p->val < root->val && q->val < root->val ) 11 return lowestCommanAncestor( root->left , p , q ); 12 if( p->val > root->val && q->val > root->val ) 13 return lowestCommanAncestor( root->right , p , q ); 14 15 return root; 16 } 17 };
相关
[235] Lowest Common Ancestor of a Binary Search Tree
原文:https://www.cnblogs.com/cxc1357/p/12684102.html