Java Simple and easy to understand solution, 0 ms, faster than 100.00% , clean code with comments
PLEASE UPVOTE IF YOU LIKE THIS SOLUTION\n\n\n\nclass Solution {\n    public int[] findRedundantConnection(int[][] edges) {\n        \n        int n = edges.leng
**PLEASE UPVOTE IF YOU LIKE THIS SOLUTION**\n\n\n```\nclass Solution {\n    public int[] findRedundantConnection(int[][] edges) {\n        \n        int n = edges.length;\n        \n        DSU dsu = new DSU(n);\n        \n        for(int[] edge : edges){\n            int nodeX = edge[0] - 1;\n            int nodeY = edge[1] - 1;\n            \n            \n            int parentX = dsu.find(nodeX);\n            int parentY = dsu.find(nodeY);\n            \n            if(parentX == parentY){\n                //same parent means, they are in the same set,\n                //same set means, all nodde already added, we can remove this one\n                return edge;\n            }\n            \n            //merge this two different set\n            dsu.unionSet(nodeX, nodeY);\n        }\n        \n        return new int[0];\n    }\n}\n\n//Disjoint Set Union\nclass DSU {\n    int[] parent;\n    \n    public DSU(int size){\n        parent = new int[size];\n        \n        //intially every element are in their set,\n        //and respresentative of their set\n        for(int i = 0; i < size; i++){\n            parent[i] = i;\n        }\n    }\n    \n    //find set of x, (Representative  of set)\n    public int find(int x){\n        if(x == parent[x])\n            return x;\n        \n        parent[x] = find(parent[x]);\n        \n        return parent[x];\n    }\n    \n    public void unionSet(int x, int y){\n        //set X\n        int parentX = find(x);\n        \n        //set Y\n        int parentY = find(y);\n        \n        //now merge the set X with set Y\n        //make parent of parent of X, with parent of y\n        parent[parentX] = parentY;\n        \n    }\n}\n```
['Union Find', 'Java']