We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 9b0ff8d commit 3ee34f9Copy full SHA for 3ee34f9
scripts/algorithms/R/Redundant Connection/Redundant Connection.js
@@ -1,15 +1,17 @@
1
+// Runtime: 123 ms (Top 34.33%) | Memory: 44.8 MB (Top 65.98%)
2
+
3
var findRedundantConnection = function(edges) {
- const root = [];
- const find = (index) => {
4
- const next = root[index];
5
- return next ? find(next) : index;
6
- };
+ const root = [];
+ const find = (index) => {
+ const next = root[index];
7
+ return next ? find(next) : index;
8
+ };
9
- for (const [a, b] of edges) {
- const x = find(a);
10
- const y = find(b);
+ for (const [a, b] of edges) {
11
+ const x = find(a);
12
+ const y = find(b);
13
- if (x === y) return [a, b];
- root[x] = y;
14
- }
+ if (x === y) return [a, b];
15
+ root[x] = y;
16
+ }
17
};
0 commit comments