We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 55d91e1 commit 60dc69bCopy full SHA for 60dc69b
14. Questions/leetcode 997 - find the town judge.py
@@ -0,0 +1,21 @@
1
+# find the town judge | leetcode 997 | https://leetcode.com/problems/find-the-town-judge/submissions/
2
+# method: decrement trust value if you trust someone, increment if someone trusts you
3
+
4
+class Solution:
5
+ def findJudge(self, n: int, trust: list[list[int]]) -> int:
6
7
+ # for each person
8
+ # trust += 1 if someone trusts you
9
+ # trust -= 1 if you trust someone
10
+ trustValue = [0] * (n + 1)
11
12
+ for edge in trust:
13
+ trustValue[edge[0]] -= 1
14
+ trustValue[edge[1]] += 1
15
16
+ for i in range(1, n + 1):
17
+ if trustValue[i] == (n - 1):
18
+ return i
19
20
+ return -1
21
0 commit comments