Skip to content

Instantly share code, notes, and snippets.

@ahmet-cetinkaya
Created January 27, 2021 15:24
Show Gist options
  • Save ahmet-cetinkaya/0c495f8f23918de9a1735686dff70b5e to your computer and use it in GitHub Desktop.
Save ahmet-cetinkaya/0c495f8f23918de9a1735686dff70b5e to your computer and use it in GitHub Desktop.
Leetcode Solution - 997. Find the Town Judge
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;
};
@ahmet-cetinkaya
Copy link
Author

Result
Runtime: 120 ms, faster than 57.32% of JavaScript online submissions for Find the Town Judge.
Memory Usage: 46.6 MB, less than 62.00% of JavaScript online submissions for Find the Town Judge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment