https://leetcode.com/problems/find-the-town-judge/description/
마을의 판사를 찾는 문제이다
주어진 조건
1.판사는 아무도 신뢰하지 않음
2.판사는 모든 마을 사람의 신뢰를 받음
신뢰하는 쪽은 빼주고 신뢰받는 쪽은 더해주어 마을 사람의 수와 같아지면 답을 반환한다
class Solution:
def findJudge(self, n: int, trust: List[List[int]]) -> int:
t= [0]*(n+1)
for a,b in trust:
t[a]-=1
t[b]+=1
for i in range(1,len(t)):
if t[i]==n-1:
return i
return -1