8000 Add Solution Python · qilingit/Leetcode@5691d52 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5691d52

Browse files
Add Solution Python
1 parent d4b2203 commit 5691d52

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

May-LeetCoding-Challenge/10-Find-The-Town-Judge/Find-The-Town-Judge.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,19 @@ def findJudge(self, N: int, trust: List[List[int]]) -> int:
1717
return -1
1818
else: # if and only if one person
1919
return candidat.pop()
20+
21+
# Solution 2 Two Arrays
22+
class Solution:
23+
def findJudge(self, N: int, trust: List[List[int]]) -> int:
24+
trusting = [0]*N
25+
trusted = [0]*N
26+
for x in trust:
27+
trusting[x[0]-1]+=1
28+
trusted[x[1]-1]+=1
29+
res = -1
30+
for i in range(N):
31+
if trusting[i]^0==0 and trusted[i]^(N-1)==0:
32+
return i+1
33+
34+
35+
return res

0 commit comments

Comments
 (0)
0