(int[][] edges)
| 2 | int totalNodes; |
| 3 | // 1 based 1,2,3 |
| 4 | public int[] findRedundantConnection(int[][] edges) { |
| 5 | totalNodes = edges.length; |
| 6 | int res[] = new int[2]; |
| 7 | DisjointSet dsu = new DisjointSet(totalNodes); |
| 8 | for (int[] edge: edges) { |
| 9 | if (!dsu.unionBySize(edge[0]-1, edge[1]-1)) { |
| 10 | return edge; |
| 11 | } |
| 12 | } |
| 13 | return res; |
| 14 | } |
| 15 | } |
| 16 | |
| 17 | public class DisjointSet { |
nothing calls this directly
no test coverage detected