Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- knakul853
- */
- class Solution {
- public:
- TreeNode* lowestCommonAncestor(TreeNode* root, TreeNode* p, TreeNode* q) {
- if( !root) return NULL;
- int val = root->val;
- if(val > p->val && val > q->val)
- return lowestCommonAncestor(root->left, p,q);
- if(val < p->val && val< q->val)
- return lowestCommonAncestor(root->right, p,q);
- return root;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement