Skip to content

Commit c0a1c82

Browse files
committed
Runtime: 1259 ms (Top 62.50%) | Memory: 51.1 MB (Top 100.00%)
1 parent 3bbdcc4 commit c0a1c82

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

scripts/algorithms/P/Process Restricted Friend Requests/Process Restricted Friend Requests.js

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Runtime: 1259 ms (Top 62.50%) | Memory: 51.1 MB (Top 100.00%)
12
/*
23
DSU Class Template
34
*/
@@ -6,20 +7,20 @@ class DSU {
67
this.parents = new Map();
78
this.rank = new Map();
89
}
9-
10+
1011
add(x) {
1112
this.parents.set(x, x);
1213
this.rank.set(x, 0);
1314
}
14-
15+
1516
find(x) {
1617
const parent = this.parents.get(x);
1718
if (parent === x) return x;
1819
const setParent = this.find(parent);
1920
this.parents.set(x, setParent);
2021
return setParent;
2122
}
22-
23+
2324
union(x, y) {
2425
const xParent = this.find(x), yParent = this.find(y);
2526
const xRank = this.rank.get(xParent), yRank = this.rank.get(yParent);
@@ -31,7 +32,7 @@ class DSU {
3132
} else {
3233
this.parents.set(xParent, yParent);
3334
this.rank.set(yParent, yRank + 1);
34-
}
35+
}
3536
}
3637
}
3738

@@ -41,7 +42,7 @@ Friend Requests
4142
var friendRequests = function(n, restrictions, requests) {
4243
const dsu = new DSU(), result = [];
4344
for (let i = 0; i < n; i++) dsu.add(i);
44-
45+
4546
for (let [friend1, friend2] of requests) {
4647
const parent1 = dsu.find(friend1), parent2 = dsu.find(friend2);
4748
let friendshipPossible = true;
@@ -58,4 +59,4 @@ var friendRequests = function(n, restrictions, requests) {
5859
result.push(friendshipPossible);
5960
}
6061
return result;
61-
};
62+
};

0 commit comments

Comments
 (0)