Skip to content

Commit 3ee34f9

Browse files
committed
Runtime: 123 ms (Top 34.33%) | Memory: 44.8 MB (Top 65.98%)
1 parent 9b0ff8d commit 3ee34f9

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1+
// Runtime: 123 ms (Top 34.33%) | Memory: 44.8 MB (Top 65.98%)
2+
13
var findRedundantConnection = function(edges) {
2-
const root = [];
3-
const find = (index) => {
4-
const next = root[index];
5-
return next ? find(next) : index;
6-
};
4+
const root = [];
5+
const find = (index) => {
6+
const next = root[index];
7+
return next ? find(next) : index;
8+
};
79

8-
for (const [a, b] of edges) {
9-
const x = find(a);
10-
const y = find(b);
10+
for (const [a, b] of edges) {
11+
const x = find(a);
12+
const y = find(b);
1113

12-
if (x === y) return [a, b];
13-
root[x] = y;
14-
}
14+
if (x === y) return [a, b];
15+
root[x] = y;
16+
}
1517
};

0 commit comments

Comments
 (0)