Skip to content

Commit

Permalink
Adding solution to challenge '997. Find the Town Judge' (easy).
Browse files Browse the repository at this point in the history
  • Loading branch information
rboyd committed Jan 23, 2023
1 parent f085f7d commit a471c5b
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions easy/find-the-town-judge/find-the-town-judge.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class Solution:
def findJudge(self, n: int, trust: List[List[int]]) -> int:
candidates = set(range(1,n+1))
trusted = defaultdict(int)
for truster, trustee in trust:
candidates.discard(truster)
trusted[trustee] += 1
for c in candidates:
if trusted[c] == n-1:
return c
return -1

0 comments on commit a471c5b

Please sign in to comment.