Description
In a town, there is exactly one judge. The judge trusts nobody, but everybody trusts the judge. Given trust relationships, find the judge or return -1.
Examples
Input:
n = 2, trust = [[1,2]]Output:
2Explanation:
Person 2 is trusted by 1.
Input:
n = 4, trust = [[1,4],[2,4],[3,4]]Output:
4Explanation:
Person 4 is trusted by persons 1, 2, and 3 (everyone else), and person 4 trusts nobody. Therefore, person 4 is the town judge.
Input:
n = 1, trust = []Output:
1Explanation:
With only one person in the town and no trust relationships, person 1 is automatically the judge since they trust nobody and are trusted by everyone (vacuously true as there's nobody else).
Constraints
- •
1 ≤ n ≤ 1000