Why root==p works but root.val==p.val does not?

  • 0
    if (root.val == p.val) or (root.val == q.val):
                return root

    The code above does not work, why?...

    if (root == p) or (root == q):
                return root

    This works

  • 1

    Tree could have duplicate value. Image a scenario that p, q on different sub tree, but p.val == q. val == root.val

Log in to reply

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