Why does [[1,2],[2,3],[3,4]] give expected output as [2,5] during submission when it gives [](correct) during testing?


  • 0
    S
    class Solution {
    public:
        // union find
        vector<int> findRedundantConnection(vector<vector<int>>& edges) {
            int n = edges.size();
            map<int, int>parent; 
            vector<int>red;
            for(auto e : edges)
            {
                int s = e[0];
                int d = e[1];
                parent[s] = s;
                if(parent.find(d) != parent.end())
                {
                    red.clear();
                    red.push_back(s);
                    red.push_back(d);
                }
                parent[d] = s;
            }
         return red;   
        }
    };
    

Log in to reply
 

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