1
var findRedundantConnection = function (edges) {
2
const root = [];
3
const find = (index) => {
4
const next = root[index];
5
return next ? find(next) : index;
6
};
7

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

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

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0