Участник:Novitskiy97/Find the Town Judge

Материал из DISCOPAL
Перейти к: навигация, поиск

https://leetcode.com/problems/find-the-town-judge/

Python 3

class Solution:
    def findJudge(self, N: int, trust: List[List[int]]) -> int:
 
        if (N == 1) and (trust == []):
            return 1
 
        trustdict={}
        for t in trust:
            if t[1] not in trustdict.keys():
                trustdict[t[1]]=[t[0]]
            else:
                trustdict[t[1]].append(t[0])
 
        for k in trustdict.keys():
            if (len(trustdict[k]) == N - 1) and (k not in [n[0] for n in trust]):
                return k
 
        return -1