Skip to content

Commit

Permalink
Time: 85 ms (71.00%) | Memory: 58.1 MB (22.50%) - LeetSync
Browse files Browse the repository at this point in the history
  • Loading branch information
ShatilKhan committed Feb 22, 2024
1 parent d97bce7 commit 37e13b9
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions 1039-find-the-town-judge/find-the-town-judge.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* @param {number} n
* @param {number[][]} trust
* @return {number}
*/
var findJudge = function(N, trust) {
const inDegree = new Array(N + 1).fill(0);
const outDegree = new Array(N + 1).fill(0);
for (let a of trust) {
outDegree[a[0]]++;
inDegree[a[1]]++;
}
for (let i = 1; i <= N; ++i) {
if (inDegree[i] === N - 1 && outDegree[i] === 0)
return i;
}
return -1;
};

0 comments on commit 37e13b9

Please sign in to comment.