Skip to content

Commit

Permalink
finish 0997
Browse files Browse the repository at this point in the history
  • Loading branch information
BLZbanme committed Dec 19, 2021
1 parent 920ec0c commit 1b0f50a
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions 0901-1000/0951-1000/0997FindTheTownJudge/demo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from typing import List
class Solution:
def findJudge(self, n: int, trust: List[List[int]]) -> int:
if n == 1 and not trust:
return 1

graph = [set() for _ in range(n + 1)]
graph2 = [set() for _ in range(n + 1)]
man = -1
for x, y in trust:
graph[y].add(x)
graph2[x].add(y)
if len(graph[y]) == n - 1:
man = y
if man == -1:
return -1
return man if not len(graph2[man]) else -1

print(Solution().findJudge(1, []))

0 comments on commit 1b0f50a

Please sign in to comment.