Problem
A town has n people labelled 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 everyone else, and at most one person can fit that description. Return the judge's label, or -1 if there is no judge.
Example 1
- Input
- n = 2, trust = [[1, 2]]
- Output
- 2
Example 2
- Input
- n = 3, trust = [[1, 3], [2, 3]]
- Output
- 3
Example 3
- Input
- n = 3, trust = [[1, 3], [2, 3], [3, 1]]
- Output
- -1
- Why
- 3 trusts someone
Constraints
1 <= n <= 10000 <= trust.length <= 10^4a != b, and no pair appears twice