174. Find the Town Judge
Easy · Graph
In a town, there are `n` people labeled from `1` to `n`. There is a rumor that one of these people is secretly the town judge. If the town judge exists, then:
1. The town judge trusts nobody. 2. Everybody else (except the town judge) trusts the town judge. 3. There is exactly one person that satisfies properties 1 and 2.
You are given an array `trust` where `trust[i] = [a, b]` means person `a` trusts person `b`. Return the label of the town judge if the town judge exists, otherwise return `-1`.
Examples
Example 1 Input: n = 3, trust = [[1,3],[2,3]] Output: 3 Explanation: Person 3 is trusted by persons 1 and 2 (everyone else), and person 3 trusts nobody. So person 3 is the town judge.
Example 2 Input: n = 3, trust = [[1,3],[2,3],[3,1]] Output: -1 Explanation: Person 3 trusts person 1, so person 3 cannot be the town judge.
Constraints
- Standard input/output constraints apply