Find the Town Judge

In a town with n people labeled from 1 to n, there is a rumor about a town judge. The town judge trusts nobody, while everyone else trusts the town judge. Only one person can satisfy these conditions. An array 'trust' represents trust relationships between people. The task is to identify the town judge or return -1 if they do not exist.

Constraints

  • 1 <= n <= 1000
  • 0 <= trust.length <= 10000
  • trust[i].length == 2
  • All the pairs of trust are unique.
  • ai != bi
  • 1 <= ai, bi <= n
Saving… · 2 lines
class Solution:
def findTownJudge(self, n: int, trust: List[List[int]]) -> int:
Console

Click Run to execute sample tests.