MCPcopy Create free account
hub / github.com/neetcode-gh/leetcode / findRedundantConnection

Method findRedundantConnection

java/0684-redundant-connection.java:5–17  ·  view source on GitHub ↗
(int[][] edges)

Source from the content-addressed store, hash-verified

3 int[] parent;
4
5 public int[] findRedundantConnection(int[][] edges) {
6 parent = new int[edges.length];
7 for (int i = 0; i < edges.length; i++) parent[i] = i + 1;
8
9 for (int[] edge : edges) {
10 if (find(edge[0]) == find(edge[1])) return edge; else union(
11 edge[0],
12 edge[1]
13 );
14 }
15
16 return new int[2];
17 }
18
19 public int find(int x) {
20 if (x == parent[x - 1]) return x;

Callers

nothing calls this directly

Calls 2

findMethod · 0.95
unionMethod · 0.95

Tested by

no test coverage detected