My 1-line Java solution


  • 4

    The solution is simple:

    return ((p.val-root.val)*(q.val-root.val)<=0) ? root : lowestCommonAncestor(p.val>root.val?root.right:root.left, p, q);

Log in to reply
 

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