leetcode997

Posted AsenYang

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了leetcode997相关的知识,希望对你有一定的参考价值。

 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

 

以上是关于leetcode997的主要内容,如果未能解决你的问题,请参考以下文章

leetcode997

LeetCode Algorithm 997. 找到小镇的法官

#Leetcode# 997. Find the Town Judge

LeetCode 997. Find the Town Judge

LeetCode --- 997. Find the Town Judge 解题报告

LeetCode --- 997. Find the Town Judge 解题报告