Created
January 27, 2021 15:24
-
-
Save ahmet-cetinkaya/0c495f8f23918de9a1735686dff70b5e to your computer and use it in GitHub Desktop.
Leetcode Solution - 997. Find the Town Judge
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const findJudge = (N, trust) => { | |
const p = new Array(N + 1).fill(0); | |
for (let [i, j] of trust) { | |
--p[i]; | |
++p[j]; | |
} | |
for (let i = 1; i < p.length; ++i) if (p[i] === N - 1) return i; | |
return -1; | |
}; |
Author
ahmet-cetinkaya
commented
Jan 27, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment