Leetcode 997. Find the Town Judge

Mingyu Jeon·2020년 5월 1일
0
post-thumbnail


class Solution:
    def findJudge(self, N: int, trust: List[List[int]]) -> int:
        if N == 1: return 1
        
        people = [0]*N
        trusted = [0]*N
        
        for i in range(len(trust)):
            people[trust[i][0]-1] += 1
            trusted[trust[i][1]-1] += 1
        
        if N-1 in trusted and 0 in people and people.index(0) == trusted.index(N-1): return trusted.index(N-1)+1
        return -1

https://leetcode.com/problems/find-the-town-judge/

0개의 댓글