要求
示例
思路
实现
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 };
相关
手机扫一扫
移动阅读更方便
你可能感兴趣的文章