We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 3014876 commit 7817495Copy full SHA for 7817495
oh-chaeyeon/7주차_그래프/Find_the_Town_Judge.js
@@ -0,0 +1,21 @@
1
+/**
2
+ * @param {number} n
3
+ * @param {number[][]} trust
4
+ * @return {number}
5
+ */
6
+var findJudge = function (n, trust) {
7
+ const trustCount = new Array(n + 1).fill(0);
8
+
9
+ for (const [a, b] of trust) {
10
+ trustCount[a]--;
11
+ trustCount[b]++;
12
+ }
13
14
+ for (let i = 1; i <= n; i++) {
15
+ if (trustCount[i] === n - 1) {
16
+ return i;
17
18
19
20
+ return -1;
21
+};
0 commit comments