Is the test case wrong


  • 0
    S

    The test case [[2,3],[5,2],[1,5][,4,2],[4,1]], apparently it shall be [4,2], why it says [4,1].
    my solution is as below, anything wrong?

    class Solution {
    public:
        vector<int> findRedundantConnection(vector<vector<int>>& edges) {
            unordered_set<int> parent,child;
            //child cannot appear twice in child, 
            for(int i=0;i<edges.size();i++)
            {
                int t0=edges[i][0],t1=edges[i][1];
                parent.insert(t0);
                if((parent.count(t1) && child.count(t0)) || child.count(t1)) //check if swap the edge exist or child appear twice
                    return edges[i];
                child.insert(t1);
            }
        }
    };
    

Log in to reply
 

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