C++ concise solution.


  • -1
    C
    TreeNode* lowestCommonAncestor(TreeNode* root, TreeNode* p, TreeNode* q) {
        if (((root->val - p->val)*(root->val - q->val)) <= 0)
            return root;
        TreeNode *kid = (root->val > p->val && root->val > q->val)?root->left:root->right;
        return lowestCommonAncestor(kid, p, q);
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.