Skip to content

Commit eaaab36

Browse files
authored
997_Find_The_Town_Judge (qiyuangong#9)
997_Find_The_Town_Judge by @sohel0707
1 parent bb4c156 commit eaaab36

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

python/997_Find_The_Town_Judge.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class Solution:
2+
def findJudge(self, N: int, trust: List[List[int]]) -> int:
3+
if N==1:
4+
return 1
5+
d1={}
6+
d2={}
7+
for i, j in trust:
8+
if j in d1:
9+
d1[j]+=1
10+
else:
11+
d1[j]=1
12+
if i in d2:
13+
d2[i]+=1
14+
else:
15+
d2[i]=1
16+
for i,j in d1.items():
17+
if j==N-1:
18+
if i not in d2:
19+
return i
20+
return -1
21+

0 commit comments

Comments
 (0)