1 class Solution:
 2     def findJudge(self, N: int, trust: 'List[List[int]]') -> int:
 3         if N==1 and len(trust)==0:
 4             return 1
 5         s = list(range(1,N+1))
 6         d = {}
 7         for t in range(len(trust)):
 8             a1 = trust[t][0]
 9             a2 = trust[t][1]
10             if a1 in s:
11                 s.remove(a1)
12             if a2 in d.keys():
13                 d.update({a2:d[a2]+1})
14             else:
15                 d.update({a2:1})
16         if len(s)==1 and s[0] in d.keys() and d[s[0]]==N-1:
17             return s[0]
18         else:
19             return -1

 

posted on 2019-02-24 12:37  Sempron2800+  阅读(120)  评论(0编辑  收藏  举报