less than 1 minute read

997. Find the Town Judge(easy)

class Solution:
    def findJudge(self, n: int, trust: List[List[int]]) -> int:
        temp = defaultdict(int)
        person = set()
        for i in range(1, n + 1):
            temp[i] = 0
        for a, b in trust:
            temp[b] += 1
            person.add(a)
        for key in temp.keys():
            # print(temp[key], key)
            if temp[key] == n - 1 and key not in person:
                return key
        return -1