Wrong judge solution for problem "Redundant Connection"


  • 0
    L

    Challenge case:
    [[1,5],[5,4],[2,4],[2,3],[1,2]]

    The judge solution returns [1,2] as the answer.

    Actually if we removed edge [1,2], there will be no parent for both node 2 and node 1, it definitely not a tree.

    The correct answer is to remove edge [5,4] or [2,4]. As [2,4] comes later, we should return [2,4]

    Tree after removing [2,4] looks like this:
    1
    | \
    2 5
    |   |
    3 4


Log in to reply
 

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