Since it is undirected, why the answer of [[2,3],[1,2],[1,3]] is 2?

  • 2

    In undirected graph, [2, 3] is equal to [3, 2], right?

    So [[2,3],[1,2],[1,3]] is equal to [1,2], [[2,3], [3,1]], right?

    I don't know how the answer of [[2,3],[1,2],[1,3]] is 2.

    Any ideas?

    Is it because the node 0, which doesn't appear in the test case, but it is actually there?

  • 0

    @zhugejunwei an "unconnected" node is still connected

  • 1

    I have the same question. Hope one can clarify the reason.

  • 0

    @zhugejunwei @yupengz1

    Yes. It's because for a valid n, there'll be alway a node 0.

    According to the given examples, it seems that for the given parameter n, it has nodes{0,.....n-1}.

    I tried test case:
    [[0,1],[1,2],[2,0]], it return 1;

Log in to reply

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