Skip to content

Commit 7817495

Browse files
committed
Find the Town Judge / 기초
1 parent 3014876 commit 7817495

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)