Skip to content

Commit

Permalink
寻找镇法官
Browse files Browse the repository at this point in the history
  • Loading branch information
rinwf committed Feb 24, 2019
1 parent c4510ca commit 339dd1b
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions 997. Find the Town Judge.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
class Solution:
def findJudge(self, N: int, trust: List[List[int]]) -> int:
if N == 1:
return 1
believe = {}
believed = {}

for a, b in trust:
if believe.get(a):
believe[a] += 1
else:
believe[a] = 1
if believed.get(b):
believed[b] += 1
else:
believed[b] = 1
for k, v in believed.items():
if v == N - 1 and believe.get(k, 0) == 0:
return k
return -1

0 comments on commit 339dd1b

Please sign in to comment.