Skip to content

Commit 1a0f620

Browse files
committed
Runtime: 1 ms (Top 89.63%) | Memory: 43.5 MB (Top 75.35%)
1 parent 61a250f commit 1a0f620

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

scripts/algorithms/R/Redundant Connection/Redundant Connection.java

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Runtime: 1 ms (Top 89.63%) | Memory: 43.5 MB (Top 75.35%)
12
class Solution {
23
public int[] findRedundantConnection(int[][] edges) {
34
UnionFind uf = new UnionFind(edges.length);
@@ -8,11 +9,11 @@ public int[] findRedundantConnection(int[][] edges) {
89
}
910
return null;
1011
}
11-
12+
1213
private class UnionFind {
1314
int[] rank;
1415
int[] root;
15-
16+
1617
UnionFind(int n) {
1718
rank = new int[n + 1];
1819
root = new int[n + 1];
@@ -21,14 +22,14 @@ private class UnionFind {
2122
rank[i] = 1;
2223
}
2324
}
24-
25+
2526
int find(int x) {
2627
if (x == root[x]) {
2728
return x;
2829
}
2930
return root[x] = find(root[x]);
3031
}
31-
32+
3233
boolean union(int x, int y) {
3334
int rootX = find(x);
3435
int rootY = find(y);
@@ -39,11 +40,11 @@ boolean union(int x, int y) {
3940
root[rootX] = root[rootY];
4041
} else {
4142
root[rootY] = root[rootX];
42-
rank[rootX]++;
43+
rank[rootX]++;
4344
}
4445
return true;
4546
}
4647
return false;
4748
}
4849
}
49-
}
50+
}

0 commit comments

Comments
 (0)