997. Find the Town Judge
Practice Find the Town Judge for free on NudgeCode: Easy, Graph pattern. Write it in Python or JavaScript, run the tests in your browser, and ask for a hint when you are stuck.
A town has n people labeled 1 to n. Each pair [a, b] in trust means person a trusts person b. The town judge, if there is one, trusts nobody, and is trusted by every other person. Return the judge's label, or -1 if no such person exists.
Example
n = 3, trust = [[1,3],[2,3]] -> 3
Constraints
- 1 <= n <= 1000
- 0 <= trust.length <= 10^4
- 1 <= a, b <= n, a != b
- All pairs in
trustare distinct